import { SwcUtils } from "../../utils/Utils.js";
class SwcHTMLVideoElementBase extends HTMLVideoElement {
  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 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());
    }
    SwcUtils.applyData(node, data, {
      asKey: this._asKey,
      asIndexKey: this._asIndexKey,
      index,
      hostContext
    });
  }
  createReactiveProxy(target, onChange, onIndexChange) {
    return SwcUtils.createReactiveProxy(target, onChange, onIndexChange);
  }
}
export {
  SwcHTMLVideoElementBase
};
//# sourceMappingURL=SwcHTMLVideoElementBase.js.map
