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 SwcHTMLEmbedElementBase_exports = {};
__export(SwcHTMLEmbedElementBase_exports, {
  SwcHTMLEmbedElementBase: () => SwcHTMLEmbedElementBase
});
module.exports = __toCommonJS(SwcHTMLEmbedElementBase_exports);
var import_Utils = require("../../utils/Utils");
class SwcHTMLEmbedElementBase extends HTMLEmbedElement {
  constructor() {
    super();
    this._masterTplNodes = [];
    this._asKey = "value";
    this._asIndexKey = "index";
  }
  getNearAppHost() {
    const hosts = this.getHosts();
    return hosts.reverse().find((host) => host.tagName.toLowerCase() === "swc-app" || host.getAttribute("is")?.startsWith("swc-app-"));
  }
  getHosts() {
    return import_Utils.SwcUtils.findAllSwcHosts(this);
  }
  getHost() {
    const hosts = this.getHosts();
    return hosts.length > 0 ? hosts[hosts.length - 1] : void 0;
  }
  getFirstHost() {
    const hosts = this.getHosts();
    return hosts.length > 0 ? hosts[0] : void 0;
  }
  getLastHost() {
    return this.getHost();
  }
  initCore() {
    this._asKey = this.getAttribute("as") || "value";
    this._asIndexKey = this.getAttribute("as-index") || "index";
    if (this._masterTplNodes.length > 0) return;
    const tplSlot = this.shadowRoot?.getElementById("tpl-slot");
    if (tplSlot) {
      this._masterTplNodes = tplSlot.assignedNodes().map((n) => n.cloneNode(true));
    } else if (this.childNodes.length > 0) {
      this._masterTplNodes = Array.from(this.childNodes).map((n) => n.cloneNode(true));
    }
  }
  applyData(node, data, index) {
    const hostContext = {};
    let curr = this.parentElement || this.getRootNode?.()?.host;
    const hostChain = [];
    while (curr) {
      if (typeof curr._getHostContext === "function") hostChain.unshift(curr);
      curr = curr.parentElement || curr.getRootNode?.()?.host;
    }
    for (const h of hostChain) {
      Object.assign(hostContext, h._getHostContext());
    }
    import_Utils.SwcUtils.applyData(node, data, {
      asKey: this._asKey,
      asIndexKey: this._asIndexKey,
      index,
      hostContext
    });
  }
  createReactiveProxy(target, onChange, onIndexChange) {
    return import_Utils.SwcUtils.createReactiveProxy(target, onChange, onIndexChange);
  }
}
//# sourceMappingURL=SwcHTMLEmbedElementBase.js.map
