import { dark } from '@dvn/alaca/theme/dark';
import { light } from '@dvn/alaca/theme/light';
import { isUserLoggedIn } from '@dvn/kimlik/index';
import { Component, h, Host, Listen, State } from '@stencil/core';
function wrapContent(theme, content) {
  return (h(Host, null,
    h("mentornity-console-app-context-injector", { theme: theme },
      h("dvn-theme-provider", { colorBackground: true, fitHeight: true, theme: theme },
        h("dvn-global-table", null),
        h("dvn-global-grid", null),
        h("dvn-global-text", null),
        h("notifier-wrapper", null, content)))));
}
export class MentornityConsoleAppRoot {
  constructor() {
    this.navigate = (config) => {
      this.path = config.path;
      history.pushState({}, '', this.path);
    };
  }
  onThemeChange(event) {
    if (event.detail === 'dvn-dark') {
      this.theme = dark;
    }
    else {
      this.theme = light;
    }
  }
  componentWillLoad() {
    const hour = new Date().getHours();
    const isSunGone = 6 > hour || hour > 18;
    this.theme = isSunGone ? dark : light;
    this.path = location.pathname;
  }
  render() {
    if (!isUserLoggedIn()) {
      return wrapContent(this.theme, h("dvn-app-anonymous", { navigate: this.navigate, path: this.path }));
    }
    return wrapContent(this.theme, h("dvn-app", { navigate: this.navigate, path: this.path }));
  }
  static get is() { return "mentornity-console-app-root"; }
  static get states() { return {
    "path": {},
    "theme": {}
  }; }
  static get listeners() { return [{
      "name": "themeChange",
      "method": "onThemeChange",
      "target": undefined,
      "capture": false,
      "passive": false
    }]; }
}
