define(["require", "exports", 'react', 'react-dom', './components/App/App', './components/App/AppState', '../utilities/router/index', './pages/GettingStartedPage/GettingStartedPage', '../utilities/resources', '../Fabric', './utilities/debugging', './app.scss', './ColorStyles.scss'], function (require, exports, React, ReactDOM, App_1, AppState_1, index_1, GettingStartedPage_1, resources_1, Fabric_1, Debugging) {
    "use strict";
    resources_1.setBaseUrl('./dist/');
    /* tslint:disable:no-string-literal */
    window['Debugging'] = Debugging;
    /* tslint:enable:no-string-literal */
    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(Fabric_1.Fabric, null, 
            React.createElement(index_1.Router, {onNewRouteLoaded: _scrollAnchorLink}, _getRoutes())
        ), rootElement);
    }
    function _getRoutes() {
        var routes = AppState_1.AppState.testPages.map(function (page) { return React.createElement(index_1.Route, {key: page.key, path: page.url, component: page.component}); });
        var appRoutes = [];
        AppState_1.AppState.examplePages.forEach(function (group) {
            group.links
                .filter(function (link) { return link.hasOwnProperty('component'); })
                .forEach(function (link, linkIndex) {
                var component = link.component;
                appRoutes.push(React.createElement(index_1.Route, {key: link.key, path: link.url, component: component}));
            });
        });
        // Default route.
        appRoutes.push(React.createElement(index_1.Route, {key: 'gettingstarted', component: GettingStartedPage_1.GettingStartedPage}));
        routes.push(React.createElement(index_1.Route, {key: 'app', component: App_1.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;
});
