"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = 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, apiActions }) => {
    const ApiWithRoutes = (jsx_runtime_1.jsx(Api, Object.assign({ appName: appName, apiConfig: apiConfig, apiActions: apiActions }, { children: jsx_runtime_1.jsx(Routes, Object.assign({}, routeProps), void 0) }), void 0));
    if (redux) {
        return jsx_runtime_1.jsx(redux.provider, Object.assign({ store: redux.store }, { children: ApiWithRoutes }), void 0);
    }
    else {
        return ApiWithRoutes;
    }
};
const AppBase = ({ Api = Api_1.Api, apiConfig, apiActions, appName, mainPath, Routes, staticRoutes, redux, onError, StyleFixes, ErrorBoundaryPage = ({ error }) => (jsx_runtime_1.jsx(StaticPages_1.DefaultPage, { appName: appName, mainPath: mainPath, body: (error === null || error === void 0 ? void 0 : error.message) || 'ErrorBoundary: Something went wrong' }, void 0)), }) => {
    const combinedStaticRoutes = [
        ...Object.values(definition_1.AppStaticRoute),
        ...Object.keys(staticRoutes || {}),
    ];
    const onReset = () => {
        window.location.reload();
    };
    return (jsx_runtime_1.jsx(react_1.Suspense, Object.assign({ fallback: "..." }, { children: jsx_runtime_1.jsxs(polymesh_ui_1.ThemeProvider, Object.assign({ theme: polymesh_ui_1.theme }, { children: [!!StyleFixes && jsx_runtime_1.jsx(StyleFixes, {}, void 0), jsx_runtime_1.jsx(react_error_boundary_1.ErrorBoundary, Object.assign({ onError: onError, onReset: onReset, FallbackComponent: ErrorBoundaryPage }, { children: jsx_runtime_1.jsx(react_router_dom_1.BrowserRouter, { children: jsx_runtime_1.jsxs(react_router_dom_1.Switch, { children: [jsx_runtime_1.jsx(react_router_dom_1.Redirect, { path: "/", exact: true, to: mainPath }, void 0), jsx_runtime_1.jsx(react_router_dom_1.Route, { path: combinedStaticRoutes, exact: true, render: (routeProps) => (jsx_runtime_1.jsx(StaticPage_1.StaticPage, { routeProps: routeProps, appName: appName, mainPath: mainPath, staticRoutes: staticRoutes, apiConfig: apiConfig }, void 0)) }, void 0), jsx_runtime_1.jsx(react_router_dom_1.Route, { path: "/:path", render: (routeProps) => (jsx_runtime_1.jsx(MainApp, { routeProps: routeProps, appName: appName, Api: Api, apiConfig: apiConfig, apiActions: apiActions, Routes: Routes, redux: redux }, void 0)) }, void 0)] }, void 0) }, void 0) }), void 0)] }), void 0) }), void 0));
};
exports.AppBase = AppBase;
//# sourceMappingURL=AppBase.js.map