import { n as o, C as c } from "../chunks/lib-cortex-element.CVMmyPMC.js";
import { c as u } from "../chunks/component.styles.CRO4Odto.js";
import { c as p } from "../chunks/custom-element.L4WJXn1j.js";
import { w as l } from "../chunks/watch.BCJD77bD.js";
import { i as b, x as f } from "../chunks/lit-element.jLBm65_O.js";
import { e as v } from "../chunks/query.BBf1UFkC.js";
const O = b`:host{display:contents}`;
var m = Object.defineProperty, y = Object.getOwnPropertyDescriptor, e = (a, i, n, r) => {
  for (var s = r > 1 ? void 0 : r ? y(i, n) : i, h = a.length - 1, d; h >= 0; h--)
    (d = a[h]) && (s = (r ? d(i, n, s) : d(s)) || s);
  return r && s && m(i, n, s), s;
};
let t = class extends c {
  constructor() {
    super(...arguments), this.attrOldValue = !1, this.charData = !1, this.charDataOldValue = !1, this.childList = !1, this.disabled = !1, this.handleMutation = (a) => {
      this.emit("cx-mutation", {
        detail: { mutationList: a }
      });
    };
  }
  connectedCallback() {
    super.connectedCallback(), this.mutationObserver = new MutationObserver(this.handleMutation), this.disabled || this.startObserver();
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.stopObserver();
  }
  startObserver() {
    const a = typeof this.attr == "string" && this.attr.length > 0, i = a && this.attr !== "*" ? this.attr.split(" ") : void 0;
    (this.mutationSlot?.assignedNodes({ flatten: !0 }) || []).forEach((r) => {
      if (r.nodeType === Node.ELEMENT_NODE)
        try {
          this.mutationObserver.observe(r, {
            attributeFilter: i,
            attributeOldValue: this.attrOldValue,
            attributes: a,
            characterData: this.charData,
            characterDataOldValue: this.charDataOldValue,
            childList: this.childList,
            subtree: !0
          });
        } catch {
        }
    });
  }
  stopObserver() {
    this.mutationObserver.disconnect();
  }
  handleDisabledChange() {
    this.disabled ? this.stopObserver() : this.startObserver();
  }
  handleSlotChange() {
    this.stopObserver(), this.startObserver();
  }
  handleChange() {
    this.stopObserver(), this.startObserver();
  }
  render() {
    return f`<slot @slotchange=${this.handleSlotChange}></slot>`;
  }
};
t.styles = [u, O];
e([
  v("slot")
], t.prototype, "mutationSlot", 2);
e([
  o({ reflect: !0 })
], t.prototype, "attr", 2);
e([
  o({ attribute: "attr-old-value", reflect: !0, type: Boolean })
], t.prototype, "attrOldValue", 2);
e([
  o({ attribute: "char-data", reflect: !0, type: Boolean })
], t.prototype, "charData", 2);
e([
  o({ attribute: "char-data-old-value", reflect: !0, type: Boolean })
], t.prototype, "charDataOldValue", 2);
e([
  o({ attribute: "child-list", reflect: !0, type: Boolean })
], t.prototype, "childList", 2);
e([
  o({ reflect: !0, type: Boolean })
], t.prototype, "disabled", 2);
e([
  l("disabled")
], t.prototype, "handleDisabledChange", 1);
e([
  l("attr", { waitUntilFirstUpdate: !0 }),
  l("attr-old-value", { waitUntilFirstUpdate: !0 }),
  l("char-data", { waitUntilFirstUpdate: !0 }),
  l("char-data-old-value", { waitUntilFirstUpdate: !0 }),
  l("childList", { waitUntilFirstUpdate: !0 })
], t.prototype, "handleChange", 1);
t = e([
  p("cx-mutation-observer")
], t);
export {
  t as default
};
