import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router-dom';
import { createHashHistory } from 'history';
import App from './App';
import { page } from './events';
import { ExplorePage, ConnectionWizardPage, SchemaPage, IndexPage, CubeBiPage, FrontendIntegrationsPage, } from './pages';
import { SecurityContextProvider } from './components/SecurityContext/SecurityContextProvider';
import { AppContextProvider } from './components/AppContext';
const history = createHashHistory();
history.listen((location) => {
    const { search, ...props } = location;
    page(props);
});
async function onTokenPayloadChange(payload, token) {
    if (token != null) {
        return token;
    }
    const response = await fetch('playground/token', {
        method: 'post',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            payload,
        }),
    });
    const json = await response.json();
    return json.token;
}
if (window.location.port === '3080' &&
    window.location.pathname.includes('/playground/live-preview/start')) {
    fetch(window.location.pathname).then(() => window.close());
}
ReactDOM.render(_jsx(Router, { history: history, children: _jsx(AppContextProvider, { playgroundContext: {
            isCloud: false,
        }, children: _jsxs(App, { children: [_jsx(Route, { exact: true, path: "/", component: IndexPage }, "index"), _jsx(Route, { path: "/build", component: (props) => {
                        return (_jsx(SecurityContextProvider, { onTokenPayloadChange: onTokenPayloadChange, children: _jsx(ExplorePage, { ...props }) }));
                    } }, "build"), _jsx(Route, { path: "/schema", component: SchemaPage }, "schema"), _jsx(Route, { path: "/connection", component: () => _jsx(ConnectionWizardPage, { history: history }) }, "connection"), _jsx(Route, { path: "/cube-bi", component: CubeBiPage }, "cube-bi"), _jsx(Route, { path: "/frontend-integrations", component: FrontendIntegrationsPage }, "frontend-integrations")] }) }) }), 
// eslint-disable-next-line no-undef
document.getElementById('playground-root'));
//# sourceMappingURL=index.js.map