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 { SwcHTMLOptGroupElementBase } from "../elements/base/SwcHTMLOptGroupElementBase.js";
let SwcForOfChildrenOptGroup = class SwcForOfChildrenOptGroup2 extends SwcHTMLOptGroupElementBase {
  constructor() {
    super(...arguments);
    this._swcValue = [];
    this._rowNodes = [];
  }
  onValueChange() {
    if (!Array.isArray(this._swcValue))
      this._swcValue = [];
    this._swcValue = this.createReactiveProxy(this._swcValue, () => this.renderAll(), (idx, v) => this.updateSingleRow(idx, v));
    if (this._masterTplNodes.length === 0)
      this.initCore();
    this.renderAll();
  }
  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.renderAll();
    }
  }
  updateSingleRow(index, newValue) {
    const nodes = this._rowNodes[index];
    if (nodes && nodes.length > 0) {
      nodes.forEach((node) => this.applyData(node, newValue, index));
    } else {
      this.renderRow(newValue, index);
    }
  }
  renderRow(item, index) {
    if (this._masterTplNodes.length === 0)
      return;
    const currentNodes = [];
    this._masterTplNodes.forEach((tplNode) => {
      const clone = tplNode.cloneNode(true);
      this.appendChild(clone);
      this.applyData(clone, item, index);
      currentNodes.push(clone);
    });
    this._rowNodes[index] = currentNodes;
  }
  renderAll() {
    this.innerHTML = "";
    this._rowNodes = [];
    this._swcValue.forEach((item, index) => this.renderRow(item, index));
  }
};
__decorate([
  attribute("swc-value"),
  __metadata("design:type", Array)
], SwcForOfChildrenOptGroup.prototype, "_swcValue", void 0);
__decorate([
  onAttributeChanged("swc-value"),
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcForOfChildrenOptGroup.prototype, "onValueChange", null);
__decorate([
  innerHtml,
  __metadata("design:type", Function),
  __metadata("design:paramtypes", []),
  __metadata("design:returntype", void 0)
], SwcForOfChildrenOptGroup.prototype, "renderTemplate", null);
SwcForOfChildrenOptGroup = __decorate([
  elementDefine({ name: "swc-for-of-children-optgroup", extends: "optgroup" })
], SwcForOfChildrenOptGroup);
export {
  SwcForOfChildrenOptGroup
};
//# sourceMappingURL=SwcForOfChildrenOptGroup.js.map
