import { Component, Host, h, Prop } from '@stencil/core';
import { setupConfig as setupSparkleConfig } from '../../services/environment/environment-config';
import { HttpService } from '../../services/httpService';
import { StudentService } from '../../services/student.service';
import { AuthStore } from "../../stores/auth.store";
export class SparkleRoot {
  async componentWillLoad() {
    setupSparkleConfig({
      sparkle: Object.assign(Object.assign({}, this.config), { prod: true })
    });
    //return Promise.reject();
    await HttpService.getInstance();
    await HttpService.init();
    if (sparkle && sparkle.auth.getToken()) {
      AuthStore.state.isAuthenticated = true;
    }
    ;
    AuthStore.onChange("isAuthenticated", async (isAuthenticated) => {
      if (isAuthenticated) {
        await StudentService.getInstance().fetchUserConfiguration();
      }
    });
    if (AuthStore.state.isAuthenticated) {
      return await StudentService.getInstance().fetchUserConfiguration();
    }
    //SignalRAspNetCoreHelper.initSignalR();
  }
  render() {
    return (h(Host, null,
      h("slot", null)));
  }
  static get is() { return "sparkle-root"; }
  static get originalStyleUrls() { return {
    "$": ["sparkle-root.css"]
  }; }
  static get styleUrls() { return {
    "$": ["sparkle-root.css"]
  }; }
  static get properties() { return {
    "config": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "EnvironmentSparkleConfig",
        "resolved": "EnvironmentSparkleConfig",
        "references": {
          "EnvironmentSparkleConfig": {
            "location": "import",
            "path": "../../services/environment/environment-config"
          }
        }
      },
      "required": true,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      }
    }
  }; }
}
