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, StyledScrollX } from 'ui/common';
import { css } from '@emotion/css';
import styled from 'styled-components';
import { RenderColumnValue, BaseColumnSpecObject } from '../common/RenderColumnValue';
import { StyledTable, StyledTd, StyledTh, StyledTr } from './styled';
var CssBox = css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  padding: 10px 20px;\n"], ["\n  padding: 10px 20px;\n"])));
var TimeLineSymbolPointer = styled.div(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  border-radius: 5px;\n  height: 10px;\n  width: 10px;\n  background-color: ", ";\n"], ["\n  border-radius: 5px;\n  height: 10px;\n  width: 10px;\n  background-color: ", ";\n"])), function (_a) {
    var theme = _a.theme;
    return theme.chain.color;
});
var TimeLineSymbolLine = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  width: 1px;\n  height: 32px;\n  background-color: ", ";\n  opacity: 0.4;\n  margin: 4px 0;\n"], ["\n  width: 1px;\n  height: 32px;\n  background-color: ", ";\n  opacity: 0.4;\n  margin: 4px 0;\n"])), function (_a) {
    var theme = _a.theme;
    return theme.chain.color;
});
var TimeLineSymbolBox = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n  display: flex;\n  justify-content: center;\n  flex-direction: column;\n  align-items: center;\n  position: relative;\n  top: 20px;\n"], ["\n  display: flex;\n  justify-content: center;\n  flex-direction: column;\n  align-items: center;\n  position: relative;\n  top: 20px;\n"])));
var TimeLineTd = styled.td(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n  vertical-align: top;\n"], ["\n  vertical-align: top;\n"])));
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.Array(Type.Any(), {
        title: 'Data',
        category: PRESET_PROPERTY_CATEGORY.Data,
        weight: 0,
        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: {
        name: 'timeline',
        displayName: 'TimeLine',
        description: 'TimeLine Components',
        exampleProperties: {
            data: [
                {
                    from: '2rGH1BB1E6fvTqiVrHMwNw8r5VrFYznvafn2Uf7amvYdCZ9f',
                    to: '2qSbd2umtD4KmV2X4zZk5QkCvmYKyiR2ysAeM1Eca6vcvg7N',
                    extrinsic_index: '10426613-1',
                },
                {
                    from: '2rGH1BB1E6fvTqiVrHMwNw8r5VrFYznvafn2Uf7amvYdCZ9f',
                    to: '2qSbd2umtD4KmV2X4zZk5QkCvmYKyiR2ysAeM1Eca6vcvg7N',
                    extrinsic_index: '10426613-2',
                },
                {
                    from: '2rGH1BB1E6fvTqiVrHMwNw8r5VrFYznvafn2Uf7amvYdCZ9f',
                    to: '2qSbd2umtD4KmV2X4zZk5QkCvmYKyiR2ysAeM1Eca6vcvg7N',
                    extrinsic_index: '10426613-3',
                },
            ],
            columns: [
                {
                    title: 'From',
                    type: 'text',
                    width: '',
                    dataKey: 'from',
                    prePath: '/account',
                    ellipsis: true,
                },
                {
                    title: 'To',
                    type: 'text',
                    width: '',
                    dataKey: 'to',
                    prePath: '/account',
                    ellipsis: true,
                },
                {
                    title: 'Extrinsic Index',
                    type: 'link',
                    width: '',
                    dataKey: 'extrinsic_index',
                    prePath: '/extrinsic',
                },
            ],
        },
        annotations: {
            category: COMPONENTS_CATEGORY.Display,
        },
    },
    spec: {
        properties: PropsSpec,
        state: {},
        methods: {},
        slots: {},
        styleSlots: ['content'],
        events: [],
    },
})(function (_a) {
    var data = _a.data, columns = _a.columns, elementRef = _a.elementRef, services = _a.services;
    return (_jsx(StyledModuleBox, __assign({ className: CssBox, ref: elementRef }, { children: _jsx(StyledScrollX, { children: _jsxs(StyledTable, __assign({ ref: elementRef }, { children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx(StyledTh, { children: " " }), columns === null || columns === void 0 ? void 0 : columns.map(function (thData, tdIndex) {
                                    return (_jsx(StyledTh, { children: _jsx(StyledFont14, __assign({ nowrap: true, bold: true }, { children: thData.title })) }, "".concat(thData.title).concat(tdIndex)));
                                })] }) }), _jsx("tbody", { children: data === null || data === void 0 ? void 0 : data.map(function (trData, trIndex) {
                            return (_jsxs(StyledTr, { children: [_jsx(TimeLineTd, { children: _jsxs(TimeLineSymbolBox, __assign({ style: { borderBottom: 0 } }, { children: [_jsx(TimeLineSymbolPointer, {}), trIndex === data.length - 1 ? null : _jsx(TimeLineSymbolLine, {})] })) }), columns.map(function (column, tdIndex) {
                                        return (_jsx(StyledTd, { children: _jsx(RenderColumnValue, __assign({ stateManager: services.stateManager, value: trData[column.dataKey] }, column)) }, "".concat(trData.title).concat(tdIndex)));
                                    })] }, "".concat(trIndex)));
                        }) })] })) }) })));
});
var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
