Liferay.Loader.define("frontend-js-spa-web@5.0.36/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 Surface extends s.Disposable{constructor(t){if(super(),!t)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=t,this.transitionFn=null,this.defaultChild=this.getChild(Surface.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 t=this.getElement();if(t&&!this.defaultChild){const e=[];t.childNodes.forEach((t=>{t.classList&&(t.classList.contains("yui3-dd-proxy")||t.classList.contains("yui3-dd-shim"))||e.push(t)}));const i=document.createDocumentFragment();e.forEach((t=>{i.appendChild(t)})),this.defaultChild=this.addContent(Surface.DEFAULT,i),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(t,e){const i=this.transitionFn||Surface.defaultTransition;return Promise.resolve(i.call(this,t,e))}}Surface.DEFAULT="default",Surface.defaultTransition=function(t,e){t&&(t.style.display="none",t.classList.remove("flipped")),e&&(e.style.display="block",e.classList.add("flipped"))};var n=Surface;e.default=n}}));
//# sourceMappingURL=Surface.js.map