import { dark } from '@dvn/alaca/theme/dark';
import { DataApiImpl } from '@dvn/core/api/dataApi';
import { KimlikApiImpl } from '@dvn/kimlik/api/kimlikApi';
import { isUserLoggedIn } from '@dvn/kimlik/index';
import { CookieStorage } from '@dvn/kimlik/storage/cookie';
import { Component, h, Host } from '@stencil/core';
import '@stencil/router';
import { DevingenApi } from '../../../api/devingen-api';
import services from '../../../configs/services';
const wrapContent = (content) => (h(Host, null,
  h("dvn-theme-provider", { theme: dark, colorBackground: true, fitHeight: true },
    h("dvn-global-table", null),
    h("dvn-global-grid", null),
    h("dvn-global-text", null),
    h("notifier-wrapper", null, content))));
export class DevingenRoot {
  render() {
    const jwt = new CookieStorage().getAll().jwt;
    const headers = {
      Authorization: jwt ? `Bearer ${new CookieStorage().getAll().jwt}` : undefined,
    };
    const apiKimlik = new KimlikApiImpl(`${services.kimlik}/${services.base}`, headers);
    const apiData = new DataApiImpl(`${services.data}/${services.base}`, headers);
    const apiDevingen = new DevingenApi(services.devingen, headers);
    if (!isUserLoggedIn()) {
      return wrapContent(h("devingen-login-page", { apiKimlik: apiKimlik }));
    }
    return wrapContent(h("devingen-router", { apiKimlik: apiKimlik, apiDevingen: apiDevingen, apiData: apiData }));
  }
  static get is() { return "devingen-root"; }
}
