import { DataApiImpl } from '@dvn/core/api/dataApi';
import { Logger } from '@dvn/core/log/logger';
import { getSessionData } from '@dvn/kimlik/index';
import { CookieStorage } from '@dvn/kimlik/storage/cookie';
import { SozlukApi } from '@dvn/sozluk/api';
import { Component, h, Host, Prop, State } from '@stencil/core';
import { KimlikApiMentornity } from '../../api/kimlik';
import { UyeApiMentornity } from '../../api/uye';
import { dataApiEndpoint, mentornityApiEndpoint } from '../../constants/env';
export class MentornityConsoleApp {
  constructor() {
    this.path = '/';
    this.navigate = (config) => {
      this.logger.debugGroup('navigate', {
        from: this.path,
        to: config.path,
      });
      this.path = config.path;
    };
  }
  componentWillLoad() {
    const defaultHeaders = {
      'Session-Token': 'NTdiMzY3NjBlNjNiY2UxZWViMDAwMDA0',
    };
    if (getSessionData().token) {
      defaultHeaders['Authorization'] = `Bearer ${getSessionData().token}`;
    }
    this.path = location.pathname;
    this.apiSozluk = new SozlukApi();
    this.storage = new CookieStorage();
    this.logger = new Logger('MentornityConsoleApp').setLevel('debug');
    this.logger.infoGroup('componentWillLoad');
    // TODO these are also set in mentornity-console-app-context-injector. WFT? I'm too tired to refactor it now.
    // this.apiAtama = new AtamaApiImpl('', defaultHeaders);
    this.apiData = new DataApiImpl(dataApiEndpoint);
    this.apiKimlik = new KimlikApiMentornity(mentornityApiEndpoint, defaultHeaders);
    this.apiUye = new UyeApiMentornity(mentornityApiEndpoint, defaultHeaders);
    this.apiSozluk = new SozlukApi();
  }
  render() {
    return (h(Host, null,
      h("dvn-app-root", { apiAtama: this.apiAtama, apiData: this.apiData, apiKimlik: this.apiKimlik, apiSozluk: this.apiSozluk, apiUye: this.apiUye, navigate: this.navigate, path: this.path, logger: this.logger, storage: this.storage })));
  }
  static get is() { return "mentornity-console-app"; }
  static get encapsulation() { return "scoped"; }
  static get assetsDirs() { return ["assets"]; }
  static get properties() { return {
    "initialPath": {
      "type": "any",
      "mutable": false,
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "initial-path",
      "reflect": false
    },
    "storageKey": {
      "type": "any",
      "mutable": false,
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "storage-key",
      "reflect": false
    }
  }; }
  static get states() { return {
    "path": {}
  }; }
}
