Liferay.Loader.define("frontend-js-spa-web@5.0.24/surface/Surface",["module","exports","require","frontend-js-web"],(function(t,e,i){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=i("frontend-js-web");class t extends n.Disposable{constructor(e){if(super(),!e)throw new Error("Surface element id not specified. A surface element requires a valid id.");this.activeChild=null,this.defaultChild=null,this.element=null,this.id=e,this.transitionFn=null,this.defaultChild=this.getChild(t.DEFAULT),this.maybeWrapContentAsDefault_(),this.activeChild=this.defaultChild}addContent(t,e){const i="string"==typeof e?(0,n.buildFragment)(e):e;Liferay.DOMTaskRunner.runTasks(i);let s=this.defaultChild;if(i){if(s=this.getChild(t),s)for(;s.firstChild;)s.removeChild(s.firstChild);else s=this.createChild(t),this.transition(s,null);s.appendChild(i)}const r=this.getElement();return r&&s&&r.appendChild(s),s}createChild(t){var e=document.createElement("div");return e.setAttribute("id",this.makeId_(t)),e}getChild(t){return document.getElementById(this.makeId_(t))}getElement(){return this.element||(this.element=document.getElementById(this.id)),this.element}getId(){return this.id}getTransitionFn(){return this.transitionFn}makeId_(t){return this.id+"-"+t}maybeWrapContentAsDefault_(){var e=this.getElement();if(e&&!this.defaultChild){for(var i=document.createDocumentFragment();e.firstChild;)i.appendChild(e.firstChild);this.defaultChild=this.addContent(t.DEFAULT,i),this.transition(null,this.defaultChild)}}setId(t){this.id=t}setTransitionFn(t){this.transitionFn=t}show(t){var e=this.activeChild,i=this.getChild(t);return i||(i=this.defaultChild),this.activeChild=i,this.transition(e,i).finally((()=>{e&&e!==i&&e.remove()}))}remove(t){var e=this.getChild(t);e&&e.remove()}toString(){return this.id}transition(e,i){var n=this.transitionFn||t.defaultTransition;return Promise.resolve(n.call(this,e,i))}}t.DEFAULT="default",t.defaultTransition=function(t,e){t&&(t.style.display="none",t.classList.remove("flipped")),e&&(e.style.display="block",e.classList.add("flipped"))};var s=t;e.default=s}}));
//# sourceMappingURL=Surface.js.map