var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
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 { initWidgetUIEditor } from '@subscan/widget-editor';
import { useMemo } from 'react';
import styled from 'styled-components';
import '@subscan/widget-editor/dist/index.css';
import runtimeConfig from 'config/runtime';
import BigNumber from 'bignumber.js';
import { useRouteLoaderData } from 'react-router-dom';
import { LocalStorageManager } from './api/localstorage/LocalStorageManager';
import { saveConfig } from './api/subscan/Services';
export { default as Record } from './Record';
export { default as Management } from './Management';
// 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 StyledContainer = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  height: 100%;\n"], ["\n  height: 100%;\n"])));
var Editor = function (_a) {
    var className = _a.className;
    var lsManager = useMemo(function () { return new LocalStorageManager(); }, []);
    var config = useRouteLoaderData('editor');
    console.log('widget data:', config);
    var CHANNEL = process.env.REACT_APP_CHANNEL;
    var Editor = initWidgetUIEditor({
        defaultApplication: config.application,
        defaultModules: lsManager.getModulesFromLS(),
        runtimeProps: runtimeConfig,
        storageHandler: {
            onSaveApp: function (app) {
                if (CHANNEL === 'subscan') {
                    saveConfig({
                        name: config.name,
                        payload: JSON.stringify(app),
                        id: config.id,
                    });
                }
                else {
                    lsManager.saveWidgetInLs(config.id.toString(), app);
                }
            },
            onSaveModules: function (modules) {
                lsManager.saveModulesInLS(modules);
            },
        },
        registerCoreComponent: false,
    }).Editor;
    return (_jsx(StyledContainer, __assign({ className: "chakraCSSReset" }, { children: _jsx(Editor, {}) })));
};
export default Editor;
var templateObject_1;
