import { Host, h } from "@stencil/core";
/**
 * Portal component to move content to end of body instead of normal DOM position. Typically used for popups
 * to prevent problems with CSS stylings.
 *
 * Does not move styles, so create a child component that has styles defined in shadow DOM.
 */
export class KlevuUtilPortal {
  connectedCallback() {
    this.createRoot();
  }
  createRoot() {
    if (this.root) {
      return;
    }
    this.root = document.createElement("div");
    const assignedContent = [];
    this.el.querySelectorAll("slot").forEach((slot) => {
      assignedContent.push(...slot.assignedElements());
    });
    this.root.appendChild(this.el);
    for (const element of assignedContent) {
      this.el.childNodes[0].appendChild(element);
    }
    this.root.setAttribute("data-name", "klevu-portal");
    document.body.appendChild(this.root);
  }
  disconnectedCallback() {
    if (!this.root) {
      return;
    }
    this.root.remove();
  }
  render() {
    return (h(Host, null, h("slot", null)));
  }
  static get is() { return "klevu-util-portal"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() {
    return {
      "$": ["klevu-util-portal.css"]
    };
  }
  static get styleUrls() {
    return {
      "$": ["klevu-util-portal.css"]
    };
  }
  static get elementRef() { return "el"; }
}
//# sourceMappingURL=klevu-util-portal.js.map
