import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { App, AppDefinition } from './AppDefinition';
import { Router, Route } from 'office-ui-fabric-react/lib/utilities/router/index';
import { GettingStartedPage } from './GettingStartedPage';
import { setBaseUrl } from 'office-ui-fabric-react/lib/Utilities';
import { ComponentPage } from '@uifabric/example-app-base';
import './index.scss';
import './ColorStyles.scss';
import { initializeIcons } from '@uifabric/icons';
initializeIcons();
setBaseUrl('./dist/');
ComponentPage.defaultProps.areBadgesVisible = true;
var rootElement;
// Return the anchor link from the URL without the hash
function _extractAnchorLink(path) {
    var index = path.lastIndexOf('#');
    if (index >= 0) {
        path = path.substr(index + 1, path.length - index);
    }
    return path;
}
function _scrollAnchorLink() {
    if ((window.location.hash.match(/#/g) || []).length > 1) {
        var anchor = _extractAnchorLink(window.location.hash);
        document.getElementById(anchor).scrollIntoView();
    }
}
function _onLoad() {
    rootElement = rootElement || document.getElementById('content');
    ReactDOM.render(React.createElement(Router, { onNewRouteLoaded: _scrollAnchorLink }, _getRoutes()), rootElement);
}
function _getRoutes() {
    var routes = AppDefinition.testPages.map(function (page) { return (React.createElement(Route, { key: page.key, path: page.url, component: page.component })); });
    var appRoutes = [];
    AppDefinition.examplePages.forEach(function (group) {
        group.links
            .filter(function (link) { return link.hasOwnProperty('component') || link.hasOwnProperty('getComponent'); })
            .forEach(function (link, linkIndex) {
            var component = link.component, getComponent = link.getComponent;
            appRoutes.push(React.createElement(Route, { key: link.key, path: link.url, component: component, getComponent: getComponent }));
        });
    });
    // Default route.
    appRoutes.push(React.createElement(Route, { key: "gettingstarted", component: GettingStartedPage }));
    routes.push(React.createElement(Route, { key: "app", component: App }, appRoutes));
    return routes;
}
function _onUnload() {
    if (rootElement) {
        ReactDOM.unmountComponentAtNode(rootElement);
    }
}
var isReady = document.readyState === 'interactive' || document.readyState === 'complete';
if (isReady) {
    _onLoad();
}
else {
    window.onload = _onLoad;
}
window.onunload = _onUnload;
//# sourceMappingURL=index.js.map