(function(){"use strict";function b(e,r){for(var o=0;o<r.length;o++){var i=r[o];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,w(i.key),i)}}function p(e,r,o){return r&&b(e.prototype,r),o&&b(e,o),Object.defineProperty(e,"prototype",{writable:!1}),e}function g(e,r){e.prototype=Object.create(r.prototype),e.prototype.constructor=e,l(e,r)}function d(e){return d=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(o){return o.__proto__||Object.getPrototypeOf(o)},d(e)}function l(e,r){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,u){return i.__proto__=u,i},l(e,r)}function y(){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 c(e,r,o){return y()?c=Reflect.construct.bind():c=function(u,a,t){var n=[null];n.push.apply(n,a);var s=Function.bind.apply(u,n),h=new s;return t&&l(h,t.prototype),h},c.apply(null,arguments)}function v(e){return Function.toString.call(e).indexOf("[native code]")!==-1}function m(e){var r=typeof Map=="function"?new Map:void 0;return m=function(i){if(i===null||!v(i))return i;if(typeof i!="function")throw new TypeError("Super expression must either be null or a function");if(typeof r<"u"){if(r.has(i))return r.get(i);r.set(i,u)}function u(){return c(i,arguments,d(this).constructor)}return u.prototype=Object.create(i.prototype,{constructor:{value:u,enumerable:!1,writable:!0,configurable:!0}}),l(u,i)},m(e)}function f(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function S(e,r){if(typeof e!="object"||e===null)return e;var o=e[Symbol.toPrimitive];if(o!==void 0){var i=o.call(e,r||"default");if(typeof i!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(e)}function w(e){var r=S(e,"string");return typeof r=="symbol"?r:String(r)}(function(e,r){var o=function(i){g(u,i);function u(){var t;return t=i.call(this)||this,t.onUserSelect="",t.onchangeStr="",t.buttonClick=t.buttonClick.bind(f(t)),t.iframeLoad=t.iframeLoad.bind(f(t)),t.modalClose=t.modalClose.bind(f(t)),t.setValue=t.setValue.bind(f(t)),t}var a=u.prototype;return a.connectedCallback=function(){this.modal=this.querySelector(this.modalClass),this.modalBody=this.querySelector(".modal-body"),this.input=this.querySelector(this.inputId),this.inputName=this.querySelector(this.inputNameClass),this.buttonSelect=this.querySelector(this.buttonSelectClass),this.modal&&window.bootstrap&&window.bootstrap.Modal&&!window.bootstrap.Modal.getInstance(this.modal)&&r.initialiseModal(this.modal,{isJoomla:!0}),this.buttonSelect&&(this.buttonSelect.addEventListener("click",this.modalOpen.bind(this)),this.modal.addEventListener("hide",this.removeIframe.bind(this)),this.onchangeStr=this.input.getAttribute("data-onchange"),this.onchangeStr&&(this.onUserSelect=new Function(this.onchangeStr),this.input.addEventListener("change",this.onUserSelect)))},a.disconnectedCallback=function(){this.onchangeStr&&this.input&&this.input.removeEventListener("change",this.onUserSelect),this.buttonSelect&&this.buttonSelect.removeEventListener("click",this),this.modal&&this.modal.removeEventListener("hide",this)},a.buttonClick=function(n){var s=n.target;this.setValue(s.getAttribute("data-user-value"),s.getAttribute("data-user-name")),this.modalClose()},a.iframeLoad=function(){var n=this,s=this.iframeEl.contentWindow.document,h=[].slice.call(s.querySelectorAll(".button-select"));h.forEach(function(_){_.addEventListener("click",n.buttonClick)})},a.modalOpen=function(){this.removeIframe();var n=document.createElement("iframe");n.setAttribute("name","field-user-modal"),n.src=this.url.replace("{field-user-id}",this.input.getAttribute("id")),n.setAttribute("width",this.modalWidth),n.setAttribute("height",this.modalHeight),this.modalBody.appendChild(n),this.modal.open(),this.iframeEl=this.modalBody.querySelector("iframe"),this.iframeEl.addEventListener("load",this.iframeLoad)},a.modalClose=function(){r.Modal.getCurrent().close(),this.modalBody.innerHTML=""},a.removeIframe=function(){this.modalBody.innerHTML=""},a.setValue=function(n,s){this.input.setAttribute("value",n),this.inputName.setAttribute("value",s||n),this.input.dispatchEvent(new Event("change")),this.dispatchEvent(new CustomEvent("change",{detail:{value:n,name:s},bubbles:!0}))},p(u,[{key:"url",get:function(){return this.getAttribute("url")},set:function(n){this.setAttribute("url",n)}},{key:"modalClass",get:function(){return this.getAttribute("modal")},set:function(n){this.setAttribute("modal",n)}},{key:"modalWidth",get:function(){return this.getAttribute("modal-width")},set:function(n){this.setAttribute("modal-width",n)}},{key:"modalHeight",get:function(){return this.getAttribute("modal-height")},set:function(n){this.setAttribute("modal-height",n)}},{key:"inputId",get:function(){return this.getAttribute("input")},set:function(n){this.setAttribute("input",n)}},{key:"inputNameClass",get:function(){return this.getAttribute("input-name")},set:function(n){this.setAttribute("input-name",n)}},{key:"buttonSelectClass",get:function(){return this.getAttribute("button-select")},set:function(n){this.setAttribute("button-select",n)}}],[{key:"observedAttributes",get:function(){return["url","modal","modal-width","modal-height","input","input-name","button-select"]}}]),u}(m(HTMLElement));e.define("joomla-field-user",o)})(customElements,Joomla)})();