Liferay.Loader.define("frontend-js-spa-web@5.0.32/surface/Surface",["module","exports","require","frontend-js-web"],(function(t,e,i){window;{Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var s=i("frontend-js-web");class t extends s.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,s.buildFragment)(e):e;Liferay.DOMTaskRunner.runTasks(i);let n=this.defaultChild;if(i){if(n=this.getChild(t),n)for(;n.firstChild;)n.removeChild(n.firstChild);else n=this.createChild(t),this.transition(n,null);n.appendChild(i)}const d=this.getElement();return d&&n&&d.appendChild(n),n}createChild(t){const 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_(){const e=this.getElement();if(e&&!this.defaultChild){const i=[];e.childNodes.forEach((t=>{t.classList&&(t.classList.contains("yui3-dd-proxy")||t.classList.contains("yui3-dd-shim"))||i.push(t)}));const s=document.createDocumentFragment();i.forEach((t=>{s.appendChild(t)})),this.defaultChild=this.addContent(t.DEFAULT,s),this.transition(null,this.defaultChild)}}setId(t){this.id=t}setTransitionFn(t){this.transitionFn=t}show(t){const e=this.activeChild;let i=this.getChild(t);return i||(i=this.defaultChild),this.activeChild=i,this.transition(e,i).finally((()=>{e&&e!==i&&e.remove()}))}remove(t){const e=this.getChild(t);e&&e.remove()}toString(){return this.id}transition(e,i){const s=this.transitionFn||t.defaultTransition;return Promise.resolve(s.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 n=t;e.default=n}}));
//# sourceMappingURL=Surface.js.map