import { n as u, C as p } from "../chunks/lib-cortex-element.CVMmyPMC.js";
import { c as h } from "../chunks/component.styles.CRO4Odto.js";
import { c as m } from "../chunks/custom-element.L4WJXn1j.js";
import { w as f } from "../chunks/watch.BCJD77bD.js";
import { i as d, x } from "../chunks/lit-element.jLBm65_O.js";
const y = d`:host{display:block}`, a = /* @__PURE__ */ new Map();
function w(t, e = "cors") {
  const r = a.get(t);
  if (r !== void 0)
    return Promise.resolve(r);
  const o = fetch(t, { mode: e }).then(async (s) => {
    const i = {
      html: await s.text(),
      ok: s.ok,
      status: s.status
    };
    return a.set(t, i), i;
  });
  return a.set(t, o), o;
}
var v = Object.defineProperty, S = Object.getOwnPropertyDescriptor, n = (t, e, r, o) => {
  for (var s = o > 1 ? void 0 : o ? S(e, r) : e, i = t.length - 1, l; i >= 0; i--)
    (l = t[i]) && (s = (o ? l(e, r, s) : l(s)) || s);
  return o && s && v(e, r, s), s;
};
let c = class extends p {
  constructor() {
    super(...arguments), this.mode = "cors", this.allowScripts = !1, this.requestInclude = w;
  }
  executeScript(t) {
    const e = document.createElement("script");
    [...t.attributes].forEach(
      (r) => e.setAttribute(r.name, r.value)
    ), e.textContent = t.textContent, t.parentNode.replaceChild(e, t);
  }
  async handleSrcChange() {
    try {
      const t = this.src, e = await this.requestInclude(t, this.mode);
      if (t !== this.src)
        return;
      if (!e.ok) {
        this.emit("cx-error", { detail: { status: e.status } });
        return;
      }
      this.innerHTML = e.html, this.allowScripts && [...this.querySelectorAll("script")].forEach(
        (r) => this.executeScript(r)
      ), this.emit("cx-load");
    } catch {
      this.emit("cx-error", { detail: { status: -1 } });
    }
  }
  render() {
    return x`<slot></slot>`;
  }
};
c.styles = [h, y];
n([
  u()
], c.prototype, "src", 2);
n([
  u()
], c.prototype, "mode", 2);
n([
  u({ attribute: "allow-scripts", type: Boolean })
], c.prototype, "allowScripts", 2);
n([
  f("src")
], c.prototype, "handleSrcChange", 1);
c = n([
  m("cx-include")
], c);
export {
  c as default
};
