import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';

const ScProvider$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.mountEmitter = createEvent(this, "mountConsumer", 7);
    this.consumers = [];
  }
  watchContext(newContext) {
    this.consumers.forEach(consumer => consumer(newContext));
  }
  async mountConsumer(event) {
    event.stopPropagation();
    this.consumers = this.consumers.slice().concat([event.detail]);
    await event.detail(this.STENCIL_CONTEXT);
    const index = this.consumers.indexOf(event.detail);
    const newConsumers = this.consumers.slice(0, index).concat(this.consumers.slice(index + 1, this.consumers.length));
    this.consumers = newConsumers;
  }
  disconnectedCallback() {
    this.consumers.map(consumer => this.mountEmitter.emit(consumer));
  }
  render() {
    return h("slot", null);
  }
  static get watchers() { return {
    "STENCIL_CONTEXT": ["watchContext"]
  }; }
}, [4, "sc-provider", {
    "STENCIL_CONTEXT": [16],
    "consumers": [32]
  }, [[0, "mountConsumer", "mountConsumer"]]]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-provider"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-provider":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScProvider$1);
      }
      break;
  } });
}
defineCustomElement$1();

const ScProvider = ScProvider$1;
const defineCustomElement = defineCustomElement$1;

export { ScProvider, defineCustomElement };
