var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from 'react';
import { ThemeProvider } from 'styled-components';
import { light, dark } from 'ui/theme';
import { ChakraProvider } from '@chakra-ui/react';
import { theme } from 'ui/chakraTheme';
import BigNumber from 'bignumber.js';
import { initWidgetUI } from '@subscan/widget-runtime';
import runtimeConfig from 'config/runtime';
import '../chakraCSSReset.css';
// This config is required for number formatting
// https://mikemcl.github.io/bignumber.js/#toS
BigNumber.config({
    EXPONENTIAL_AT: 1000,
    DECIMAL_PLACES: 80,
    ROUNDING_MODE: 1,
});
var Preview = function (_a) {
    var options = _a.options, isDark = _a.isDark, chainStyles = _a.chainStyles;
    var App = initWidgetUI(runtimeConfig).App;
    var initTheme = useMemo(function () {
        var defaultStyles = isDark ? dark : light;
        if (chainStyles && (chainStyles === null || chainStyles === void 0 ? void 0 : chainStyles.dark) && (chainStyles === null || chainStyles === void 0 ? void 0 : chainStyles.light)) {
            defaultStyles.chain = __assign(__assign({}, defaultStyles.chain), (isDark ? chainStyles === null || chainStyles === void 0 ? void 0 : chainStyles.dark : chainStyles === null || chainStyles === void 0 ? void 0 : chainStyles.light));
        }
        return isDark ? dark : light;
    }, [chainStyles, isDark]);
    return (_jsx(ChakraProvider, __assign({ theme: theme, resetCSS: false }, { children: _jsx(ThemeProvider, __assign({ theme: initTheme }, { children: _jsx("div", __assign({ className: "chakraCSSReset" }, { children: options && _jsx(App, { options: options }) })) })) })));
};
export default Preview;
