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);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { Type } from '@sinclair/typebox';
import { Balance, Link, Status, Text, Time, EllipsisText, Tag, Code } from 'components';
import { PRESET_PROPERTY_CATEGORY } from 'config/constants';
import { StyledFont12 } from 'ui/common';
import { toShortString } from 'utils';
import { Tooltip, Box } from '@chakra-ui/react';
export var BaseColumnSpecObject = {
    transformer: Type.Optional(Type.String({
        title: 'Transformer',
        description: "$value + 'test'",
    })),
    type: Type.KeyOf(Type.Object({
        text: Type.String(),
        link: Type.String(),
        transactionStatus: Type.String(),
        balance: Type.String(),
        time: Type.String(),
        tag: Type.String(),
        code: Type.String(),
    }), {
        title: 'Type',
        category: PRESET_PROPERTY_CATEGORY.Basic,
    }),
    prePath: Type.Optional(Type.String({
        title: 'URL prefix',
        conditions: [
            {
                key: 'type',
                value: 'link',
            },
        ],
    })),
    ellipsis: Type.Optional(Type.Boolean({
        title: 'Ellipsis',
        conditions: [
            {
                or: [
                    {
                        key: 'type',
                        value: 'link',
                    },
                    {
                        key: 'type',
                        value: 'text',
                    },
                ],
            },
        ],
    })),
    decimals: Type.Optional(Type.Number({
        title: 'Token Decimals',
        conditions: [
            {
                key: 'type',
                value: 'balance',
            },
        ],
    })),
    tagstyle: Type.Optional(Type.KeyOf(Type.Object({
        primary: Type.String(),
        secondary: Type.String(),
    }), {
        title: 'Tag Style',
        conditions: [
            {
                key: 'type',
                value: 'tag',
            },
        ],
    })),
    symbol: Type.Optional(Type.String({
        title: 'Token Symbol',
        conditions: [
            {
                key: 'type',
                value: 'balance',
            },
        ],
    })),
};
export var BaseColumnSpec = Type.Object(BaseColumnSpecObject);
export var RenderColumnValue = function (_a) {
    var stateManager = _a.stateManager, type = _a.type, value = _a.value, transformer = _a.transformer, rest = __rest(_a, ["stateManager", "type", "value", "transformer"]);
    var transformerValue = transformer
        ? stateManager.deepEval("{{".concat(transformer, "}}") || '', { scopeObject: { $value: value } }).toString()
        : value;
    // const transformerValue = transformer ? new Function('value', transformer)(value) : value;
    var _b = rest.ellipsis, ellipsis = _b === void 0 ? true : _b, _c = rest.prePath, prePath = _c === void 0 ? '' : _c, _d = rest.decimals, decimals = _d === void 0 ? 0 : _d, symbol = rest.symbol, tagstyle = rest.tagstyle;
    switch (type) {
        case 'text':
            return (_jsx(_Fragment, { children: ellipsis ? (_jsx(EllipsisText, { ellipsis: ellipsis, text: transformerValue })) : (_jsx(Text, { children: transformerValue === null || transformerValue === void 0 ? void 0 : transformerValue.toString() })) }));
        case 'transactionStatus':
            return _jsx(Status, { type: transformerValue });
        case 'link':
            var to = prePath ? "".concat(prePath, "/").concat(transformerValue) : "/".concat(transformerValue);
            var displayName = ellipsis ? toShortString(transformerValue) : transformerValue;
            return (_jsx(_Fragment, { children: ellipsis ? (_jsx(Link, __assign({ href: to }, { children: _jsx(Tooltip, __assign({ hasArrow: true, bg: "#fff", placement: "top", label: _jsx(Box, __assign({ p: "2" }, { children: _jsx(StyledFont12, { children: transformerValue }) })) }, { children: displayName })) }))) : (_jsx(Link, __assign({ href: to }, { children: displayName }))) }));
        case 'time':
            return _jsx(Time, { second: parseInt(transformerValue) });
        case 'balance':
            return _jsx(Balance, { value: transformerValue, decimals: decimals, symbol: symbol });
        case 'tag':
            return _jsx(Tag, { text: transformerValue, variant: tagstyle });
        case 'code':
            return _jsx(Code, { code: transformerValue });
        default:
            return _jsx(Text, { children: transformerValue === null || transformerValue === void 0 ? void 0 : transformerValue.toString() });
    }
};
