import { Component, Event, h, Listen, Prop, State, Watch } from '@stencil/core';
export class ScProvider {
  constructor() {
    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 is() { return "sc-provider"; }
  static get properties() { return {
    "STENCIL_CONTEXT": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "{ [key: string]: any }",
        "resolved": "{ [key: string]: any; }",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
  static get states() { return {
    "consumers": {}
  }; }
  static get events() { return [{
      "method": "mountEmitter",
      "name": "mountConsumer",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
  static get watchers() { return [{
      "propName": "STENCIL_CONTEXT",
      "methodName": "watchContext"
    }]; }
  static get listeners() { return [{
      "name": "mountConsumer",
      "method": "mountConsumer",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
