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 { SwcHTMLBodyElementBase } from "../elements/base/SwcHTMLBodyElementBase.js";
let SwcIfChildrenBody = class SwcIfChildrenBody2 extends SwcHTMLBodyElementBase {
  constructor() {
    super(...arguments);
    this._swcValue = false;
  }
  onValueChange() {
    if (this._masterTplNodes.length === 0)
      this.initCore();
    this.render();
  }
  set swcValue(val) {
    this._swcValue = val;
  }
  get swcValue() {
    return this._swcValue;
  }
  renderTemplate() {
    return `<slot id="tpl-slot" style="display:none;"></slot>`;
  }
  connectedCallback() {
    this.initCore();
    if (this._masterTplNodes.length > 0) {
      this.innerHTML = "";
      this.render();
    }
  }
  render() {
    const attrValue = this.getAttribute("swc-value") || this.getAttribute("value");
    if (attrValue !== null && attrValue.includes("{{"))
      return;
    let displayValue = attrValue !== null ? attrValue : this._swcValue;
    let isTruthy = !!displayValue;
    if (typeof displayValue === "string") {
      if (displayValue === "false" || displayValue === "0" || displayValue === "")
        isTruthy = false;
      else {
        try {
          isTruthy = !!new Function("return " + displayValue)();
        } catch (e) {
          isTruthy = true;
        }
      }
    }
    this.innerHTML = "";
    if (isTruthy && this._masterTplNodes.length > 0) {
      this._masterTplNodes.forEach((tplNode) => {
        const clone = tplNode.cloneNode(true);
        this.appendChild(clone);
        if (clone.style)
          clone.style.display = "contents";
        this.applyData(clone, this._swcValue);
      });
    }
  }
};
__decorate([
  attribute("swc-value"),
  __metadata("design:type", Object)
], SwcIfChildrenBody.prototype, "_swcValue", void 0);
__decorate([
  onAttributeChanged("swc-value"),
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcIfChildrenBody.prototype, "onValueChange", null);
__decorate([
  innerHtml,
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcIfChildrenBody.prototype, "renderTemplate", null);
SwcIfChildrenBody = __decorate([
  elementDefine({ name: "swc-if-children-body", extends: "body" })
], SwcIfChildrenBody);
export {
  SwcIfChildrenBody
};
//# sourceMappingURL=SwcIfChildrenBody.js.map
