var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var SwcIfStyle_exports = {};
__export(SwcIfStyle_exports, {
  SwcIfStyle: () => SwcIfStyle
});
module.exports = __toCommonJS(SwcIfStyle_exports);
var import__ = require("../index");
var import_SwcHTMLStyleElementBase = require("../elements/base/SwcHTMLStyleElementBase");
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);
};
let SwcIfStyle = class SwcIfStyle2 extends import_SwcHTMLStyleElementBase.SwcHTMLStyleElementBase {
  constructor() {
    super(...arguments);
    this._placeholder = document.createComment("swc-if-placeholder");
    this._isShowing = true;
    this._isInitialized = false;
    this._swcValue = false;
  }
  onValueChange() {
    this.evaluate();
  }
  set swcValue(val) {
    this._swcValue = val;
  }
  get swcValue() {
    return this._swcValue;
  }
  connectedCallback() {
    if (this._isInitialized)
      return;
    this._isInitialized = true;
    this.evaluate();
  }
  evaluate() {
    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;
        }
      }
    }
    if (!isTruthy && this._isShowing) {
      if (this.parentNode) {
        this.parentNode.insertBefore(this._placeholder, this);
        this.remove();
        this._isShowing = false;
      }
    } else if (isTruthy && !this._isShowing) {
      if (this._placeholder.parentNode) {
        this._placeholder.parentNode.insertBefore(this, this._placeholder);
        this._placeholder.remove();
        this._isShowing = true;
      }
    }
  }
};
__decorate([
  (0, import__.attribute)("swc-value"),
  __metadata("design:type", Object)
], SwcIfStyle.prototype, "_swcValue", void 0);
__decorate([
  (0, import__.onAttributeChanged)("swc-value"),
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcIfStyle.prototype, "onValueChange", null);
SwcIfStyle = __decorate([
  (0, import__.elementDefine)({ name: "swc-if-style", extends: "style" })
], SwcIfStyle);
//# sourceMappingURL=SwcIfStyle.js.map
