import {
  __decorateClass
} from "../../chunks/chunk.QU3DSPNU.js";
import { property } from "lit/decorators.js";
import { GdsElement } from "../../gds-element.js";
import { gdsCustomElement } from "../../scoping.js";
import { tokens } from "../../tokens.style.js";
import { observeLightDOM } from "../../utils/decorators/index.js";
import {
  withLayoutChildProps,
  withMarginProps
} from "../../utils/mixins/declarative-layout-mixins.js";
import { defaultStyles } from "../text/default-typography.styles.js";
import styles from "./rich-text.styles.js";
let GdsRichText = class extends withLayoutChildProps(
  withMarginProps(GdsElement)
) {
  constructor() {
    super(...arguments);
    this.captureMode = "clone";
  }
  /**
   * Forwards the selector to the corresponding function on the inner shadowRoot.
   */
  querySelectorAll(selector) {
    if (!this.shadowRoot) return new NodeList();
    return this.shadowRoot.querySelectorAll(selector);
  }
  /**
   * Forwards the selector to the corresponding function on the inner shadowRoot.
   */
  querySelector(selector) {
    if (!this.shadowRoot) return null;
    return this.shadowRoot.querySelector(selector);
  }
  /**
   * Forwards innerHTML from the inner shadowRoot.
   */
  get innerHTML() {
    return this.shadowRoot?.innerHTML || "";
  }
  set innerHTML(value) {
    if (!this.shadowRoot) return;
    this.shadowRoot.innerHTML = value;
  }
  connectedCallback() {
    super.connectedCallback();
    this._captureDOM();
  }
  _captureDOM() {
    if (!this.shadowRoot || this.childNodes.length === 0) return;
    if (this.captureMode === "move") {
      this.shadowRoot.replaceChildren(...Array.from(this.childNodes));
      return;
    }
    const cloned = Array.from(this.childNodes).map(
      (node) => node.cloneNode(true)
    );
    this.shadowRoot.replaceChildren(...cloned);
  }
};
GdsRichText.styles = [tokens, defaultStyles, styles];
__decorateClass([
  property()
], GdsRichText.prototype, "captureMode", 2);
__decorateClass([
  observeLightDOM({
    childList: true,
    subtree: true,
    attributes: true,
    characterData: true
  })
], GdsRichText.prototype, "_captureDOM", 1);
GdsRichText = __decorateClass([
  gdsCustomElement("gds-rich-text")
], GdsRichText);
export {
  GdsRichText
};
