var __decorate = function(decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = function(k, v) {
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { attribute, elementDefine, innerHtml, onAttributeChanged } from "../index.js";
import { SwcHTMLElementBase } from "./base/SwcHTMLElementBase.js";
let SwcObject = class SwcObject2 extends SwcHTMLElementBase {
  constructor() {
    super();
    this._swcValue = {};
    this._renderedNodes = [];
  }
  onValueChange() {
    if (typeof this._swcValue !== "object" || this._swcValue === null)
      this._swcValue = {};
    this._swcValue = this.createReactiveProxy(this._swcValue, () => {
      this.updateUI();
    });
    if (this._masterTplNodes.length === 0)
      this.initCore();
    this.render();
  }
  set swcValue(val) {
    this._swcValue = val;
  }
  get swcValue() {
    return this._swcValue;
  }
  renderTemplate() {
    return `
      <style>:host { display: contents; }</style>
      <slot id="tpl-slot" style="display:none;"></slot>
    `;
  }
  connectedCallback() {
    this.initCore();
    this.render();
  }
  updateUI() {
    this._renderedNodes.forEach((node) => {
      this.applyData(node, this._swcValue);
    });
  }
  render() {
    this.innerHTML = "";
    this._renderedNodes = [];
    if (!this.shadowRoot || this._masterTplNodes.length === 0)
      return;
    let slot = this.shadowRoot.querySelector('slot[name="obj-content"]');
    if (!slot) {
      slot = document.createElement("slot");
      slot.name = "obj-content";
      this.shadowRoot.appendChild(slot);
    }
    this._masterTplNodes.forEach((tplNode) => {
      const clone = tplNode.cloneNode(true);
      if (clone.nodeType === Node.ELEMENT_NODE) {
        clone.setAttribute("slot", "obj-content");
      } else if (clone.nodeType === Node.TEXT_NODE) {
        if (clone.textContent?.trim().length === 0)
          return;
        const span = document.createElement("span");
        span.setAttribute("slot", "obj-content");
        span.appendChild(clone);
        this.appendChild(span);
        this._renderedNodes.push(span);
        this.applyData(span, this._swcValue);
        return;
      }
      this.appendChild(clone);
      this._renderedNodes.push(clone);
      this.applyData(clone, this._swcValue);
    });
  }
};
__decorate([
  attribute("swc-value"),
  __metadata("design:type", Object)
], SwcObject.prototype, "_swcValue", void 0);
__decorate([
  onAttributeChanged("swc-value"),
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcObject.prototype, "onValueChange", null);
__decorate([
  innerHtml({ useShadow: true }),
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcObject.prototype, "renderTemplate", null);
SwcObject = __decorate([
  elementDefine({ name: "swc-object" }),
  __metadata("design:paramtypes", [])
], SwcObject);
export {
  SwcObject
};
//# sourceMappingURL=SwcObject.js.map
