import 'normalize.css';
import '../lib/util.css';
import './util.css';
import rem from '../lib/rem';
import * as dialog from '../lib/dialog';
import { NavPage, Nav } from './nav';
import * as ReactDom from 'react-dom';
import * as React from 'react';
import { Component } from 'react';
import _404 from './404';
import { ViewController } from '../lib/ctr';
import { NavDataPage } from './page';
export class Root extends ViewController {
    constructor() {
        super(...arguments);
        this.loadingText = 'Loading..';
        this.startupPath = '/';
    }
    async triggerLoad() {
        rem.initialize(this.props.scale);
        window.addEventListener('hashchange', (e) => {
            this.refs.nav.current.popPage(true);
        });
    }
    triggerNav(e) {
        var title = this.props.title || '';
        if (e.action == 'pop') {
        }
        else if (e.action == 'push') {
            window.history.pushState({}, title, '#' + e.pathname);
        }
        else {
            window.history.replaceState({}, title, '#' + e.pathname);
        }
    }
    triggerEnd() {
    }
    render() {
        var url = this.startupPath || (location.hash ? location.hash.replace(/^#/, '') : '/');
        var routes = this.props.routes || [];
        return (this.isLoaded ?
            React.createElement(Nav, { ref: "nav", notFound: this.props.notFound || _404, routes: routes, onNav: e => this.triggerNav(e), onEnd: () => this.triggerEnd(), initURL: url }) :
            React.createElement("div", { className: "init-loading" }, this.loadingText));
    }
}
export { React, ReactDom, Component, Nav, NavPage, dialog, NavDataPage, };
