"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppBase = void 0;
const react_1 = __importStar(require("react"));
const react_router_dom_1 = require("react-router-dom");
const react_error_boundary_1 = require("react-error-boundary");
const polymesh_ui_1 = require("@polymathnetwork/polymesh-ui");
const StaticPage_1 = require("./StaticPage");
const StaticPages_1 = require("./StaticPages");
const Api_1 = require("./Api");
const definition_1 = require("./definition");
const MainApp = ({ appName, Api, apiConfig, Routes, redux, routeProps }) => {
    return (react_1.default.createElement(redux.provider, { store: redux.store },
        react_1.default.createElement(Api, { appName: appName, apiConfig: apiConfig, redux: redux },
            react_1.default.createElement(Routes, Object.assign({}, routeProps)))));
};
exports.AppBase = ({ Api = Api_1.Api, apiConfig, appName, mainPath, Routes, staticRoutes, redux, onError, StyleFixes, ErrorBoundaryPage = ({ error }) => (react_1.default.createElement(StaticPages_1.DefaultPage, { appName: appName, mainPath: mainPath, body: (error === null || error === void 0 ? void 0 : error.message) || 'ErrorBoundary: Something went wrong' })), }) => {
    const combinedStaticRoutes = [
        ...Object.values(definition_1.AppStaticRoute),
        ...Object.keys(staticRoutes || {}),
    ];
    const onReset = () => {
        window.location.reload();
    };
    return (react_1.default.createElement(react_1.Suspense, { fallback: "..." },
        react_1.default.createElement(polymesh_ui_1.ThemeProvider, { theme: polymesh_ui_1.theme },
            !!StyleFixes && react_1.default.createElement(StyleFixes, null),
            react_1.default.createElement(react_error_boundary_1.ErrorBoundary, { onError: onError, onReset: onReset, FallbackComponent: ErrorBoundaryPage },
                react_1.default.createElement(react_router_dom_1.BrowserRouter, null,
                    react_1.default.createElement(react_router_dom_1.Switch, null,
                        react_1.default.createElement(react_router_dom_1.Route, { path: combinedStaticRoutes, exact: true, render: (routeProps) => (react_1.default.createElement(StaticPage_1.StaticPage, { routeProps: routeProps, appName: appName, mainPath: mainPath, staticRoutes: staticRoutes, apiConfig: apiConfig })) }),
                        react_1.default.createElement(react_router_dom_1.Route, { path: "/:path", render: (routeProps) => (react_1.default.createElement(MainApp, { routeProps: routeProps, appName: appName, Api: Api, apiConfig: apiConfig, Routes: Routes, redux: redux })) })))))));
};
//# sourceMappingURL=AppBase.js.map