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, jsxs as _jsxs } from "react/jsx-runtime";
import { Type } from '@sinclair/typebox';
import { implementRuntimeComponent } from '@subscan/widget-runtime';
import { COMPONENTS_CATEGORY, PRESET_PROPERTY_CATEGORY, VERSION } from 'config/constants';
import { StyledFont14, StyledModuleBox } from 'ui/common';
import { css, cx } from '@emotion/css';
import styled from 'styled-components';
import { RenderColumnValue, BaseColumnSpecObject } from '../common/RenderColumnValue';
import { FALLBACK_METADATA, getComponentProps } from 'utils/widget-helper';
var CssBox = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  padding: 10px 20px;\n"], ["\n  padding: 10px 20px;\n"])));
var StyledColumn = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  display: flex;\n  border-bottom: 1px solid ", ";\n  padding: 10px;\n  flex-direction: column;\n  p,\n  a {\n    word-break: break-all;\n  }\n\n  ", " {\n    flex-direction: row;\n    padding: 15px 10px;\n  }\n"], ["\n  display: flex;\n  border-bottom: 1px solid ", ";\n  padding: 10px;\n  flex-direction: column;\n  p,\n  a {\n    word-break: break-all;\n  }\n\n  ", " {\n    flex-direction: row;\n    padding: 15px 10px;\n  }\n"])), function (_a) {
    var theme = _a.theme;
    return theme.colors.background04;
}, function (_a) {
    var theme = _a.theme;
    return theme.mediaQueries.md;
});
var StyledColumnHeader = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  width: 180px;\n  flex-shrink: 0;\n  margin-bottom: 10px;\n  ", " {\n    margin-bottom: 0;\n  }\n"], ["\n  width: 180px;\n  flex-shrink: 0;\n  margin-bottom: 10px;\n  ", " {\n    margin-bottom: 0;\n  }\n"])), function (_a) {
    var theme = _a.theme;
    return theme.mediaQueries.md;
});
export var ColumnSpec = Type.Object(__assign({ title: Type.String({
        title: 'Title',
        category: PRESET_PROPERTY_CATEGORY.Basic,
    }), width: Type.String({
        title: 'Width',
    }), dataKey: Type.String({
        title: 'Key',
        category: PRESET_PROPERTY_CATEGORY.Basic,
        description: 'The key corresponding to the column data in the data item is used to display the value',
    }) }, BaseColumnSpecObject));
var PropsSpec = Type.Object({
    data: Type.Record(Type.String(), Type.Any(), {
        title: 'Data',
        category: PRESET_PROPERTY_CATEGORY.Data,
        weight: 1,
        widget: 'core/v1/expression',
    }),
    columns: Type.Array(ColumnSpec, {
        title: 'Columns',
        description: '',
        category: PRESET_PROPERTY_CATEGORY.Columns,
        widget: 'core/v1/array',
        widgetOptions: {
            displayedKeys: ['title'],
        },
        weight: 0,
    }),
});
export default implementRuntimeComponent({
    version: VERSION.Core,
    metadata: __assign(__assign({}, FALLBACK_METADATA), { name: 'constraintlist', displayName: 'Constraint List', description: 'Constraint List Components', exampleProperties: {
            data: {
                from: '2rGH1BB1E6fvTqiVrHMwNw8r5VrFYznvafn2Uf7amvYdCZ9f',
                to: '2qSbd2umtD4KmV2X4zZk5QkCvmYKyiR2ysAeM1Eca6vcvg7N',
                extrinsic_index: '10426613-1',
                success: false,
                hash: '0x4b786c3d4740fcb90bfa593c1335a65fc2ff425114b3060ae377b6981c50e3d8',
                block_num: 10426613,
                block_timestamp: 1664176458,
                module: 'balances',
                amount: '86.13245',
                amount_v2: '86132450000',
                fee: '114600000',
                nonce: 7,
                asset_symbol: '',
                asset_type: '',
                from_account_display: { address: '2rGH1BB1E6fvTqiVrHMwNw8r5VrFYznvafn2Uf7amvYdCZ9f' },
                to_account_display: {
                    address: '2qSbd2umtD4KmV2X4zZk5QkCvmYKyiR2ysAeM1Eca6vcvg7N',
                    display: '0x245b4775082c144c22a4874b0fba8c70c510c5ae',
                },
                event_idx: 1,
            },
            columns: [
                {
                    title: 'Extrinsic ID',
                    type: 'link',
                    width: '',
                    dataKey: 'extrinsic_index',
                    prePath: '/extrinsic',
                    ellipsis: false,
                },
                {
                    title: 'Block',
                    type: 'link',
                    width: '',
                    dataKey: 'block_num',
                    prePath: '/block',
                    ellipsis: false,
                },
                {
                    title: 'Time',
                    type: 'time',
                    width: '',
                    dataKey: 'block_timestamp',
                },
                {
                    title: 'From',
                    type: 'link',
                    width: '',
                    dataKey: 'from',
                    prePath: '/account',
                },
                {
                    title: 'To',
                    type: 'link',
                    width: '',
                    dataKey: 'to',
                    prePath: '/account',
                },
                {
                    title: 'Value',
                    type: 'balance',
                    width: '',
                    dataKey: 'amount_v2',
                    decimals: 9,
                    symbol: 'RING',
                },
                {
                    title: 'Result',
                    type: 'transactionStatus',
                    width: '',
                    dataKey: 'success',
                    transformer: "return value == 'true' ? 'normal' : 'error'",
                },
                {
                    title: 'Hash',
                    type: 'link',
                    width: '',
                    dataKey: 'hash',
                    prePath: '/extrinsic',
                    ellipsis: true,
                },
            ],
        }, annotations: {
            category: COMPONENTS_CATEGORY.Display,
        } }),
    spec: {
        properties: PropsSpec,
        state: {},
        methods: {},
        slots: {},
        styleSlots: ['content'],
        events: [],
    },
})(function (props) {
    var _a = getComponentProps(props), data = _a.data, columns = _a.columns;
    var elementRef = props.elementRef, customStyle = props.customStyle, services = props.services;
    return (_jsx(StyledModuleBox, __assign({ className: cx(css(customStyle === null || customStyle === void 0 ? void 0 : customStyle.content), CssBox), ref: elementRef }, { children: columns === null || columns === void 0 ? void 0 : columns.map(function (column, index) {
            return (_jsxs(StyledColumn, { children: [_jsx(StyledColumnHeader, { children: _jsx(StyledFont14, __assign({ bold: true }, { children: column.title })) }), _jsx("div", { children: _jsx(RenderColumnValue, __assign({ stateManager: services.stateManager, value: data[column.dataKey] }, column)) })] }, "".concat(column.title).concat(index)));
        }) })));
});
var templateObject_1, templateObject_2, templateObject_3;
