"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = __importStar(require("react"));
const ReactDOM = __importStar(require("react-dom"));
const apollo_link_http_1 = require("apollo-link-http");
const apollo_client_1 = require("apollo-client");
const apollo_cache_inmemory_1 = require("apollo-cache-inmemory");
const react_apollo_1 = require("react-apollo");
const nav_1 = __importDefault(require("./components/nav"));
const apollo_link_1 = require("apollo-link");
const react_1 = require("react");
const react_router_dom_1 = require("react-router-dom");
const home_1 = __importDefault(require("./pages/home"));
const botbuilder_1 = __importDefault(require("./pages/botbuilder"));
const callback_1 = __importDefault(require("./pages/callback"));
const config_1 = __importDefault(require("@botsbotsbots/common/config"));
require("./stylesheets/bbb/nav.scss");
const auth_1 = require("./utils/auth");
const link = apollo_link_http_1.createHttpLink({
    uri: config_1.default.app.api
});
const middlewareLink = new apollo_link_1.ApolloLink((operation, forward) => {
    // get the authentication token from local storage if it exists
    const id_token = auth_1.getIdToken();
    // return the headers to the context so httpLink can read them
    operation.setContext({
        headers: {
            Authorization: id_token ? `Bearer ${id_token}` : ''
        }
    });
    return forward(operation);
});
const client = new apollo_client_1.ApolloClient({
    cache: new apollo_cache_inmemory_1.InMemoryCache(),
    link: apollo_link_1.ApolloLink.from([middlewareLink.concat(link)])
});
const WithProvider = (client) => (React.createElement(react_apollo_1.ApolloProvider, { client: client },
    React.createElement(react_router_dom_1.BrowserRouter, null,
        React.createElement(react_1.Fragment, null,
            React.createElement(nav_1.default, null),
            React.createElement("div", { className: "fl w-100 pl4 pr4" },
                React.createElement(react_router_dom_1.Switch, null,
                    React.createElement(react_router_dom_1.Route, { exact: true, path: "/", component: home_1.default }),
                    React.createElement(react_router_dom_1.Route, { path: "/callback", component: callback_1.default }),
                    React.createElement(react_router_dom_1.Route, { path: "/bots/:emoji_id", component: botbuilder_1.default }),
                    React.createElement(react_router_dom_1.Route, { path: "/bots", component: botbuilder_1.default })))))));
function withAuth() {
    return ReactDOM.render(WithProvider(client), document.getElementById('root'));
}
withAuth();
//# sourceMappingURL=index.js.map