import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { Check, Minus } from '@gravity-ui/icons';
import { Icon } from '@gravity-ui/uikit';
import { HTML, YFMWrapper } from "../index.js";
import { block } from "../../utils/index.js";
import './Table.css';
function getMarkerId(index) {
    if (isNaN(index)) {
        return undefined;
    }
    return `marker-${index}`;
}
const b = block('table');
export default class Table extends React.Component {
    render() {
        const { content, legend, hideLegend, marker = 'disk', className, caption } = this.props;
        if (!content || !content.length || !content[0].length) {
            return null;
        }
        return (_jsxs("div", { className: b(null, className), role: 'table', "aria-label": caption, children: [this.renderTable(content, marker, legend), legend && !hideLegend && this.renderLegend(legend, marker)] }));
    }
    renderTable(content, marker, legend) {
        const justify = this.getDefaultJustify(content, this.props.justify);
        return (_jsx("div", { className: b('table'), role: 'rowgroup', children: content.map((row, i) => (_jsx("div", { className: b('row'), role: 'row', children: row.map((cell, j) => (_jsx("div", { className: b('cell', { justify: justify[j] }), role: 'cell', children: legend && i && j ? (this.renderMarker(marker, cell)) : (_jsx(HTML, { children: cell })) }, j))) }, i))) }));
    }
    renderMarker(type, cell) {
        return (_jsx("div", { "aria-labelledby": getMarkerId(Number(cell)), className: b('marker', { type, index: String(cell) }), children: type === 'tick' ? (_jsx(Icon, { size: 20, className: b('marker_tick', { check: Number(cell) === 1 }), data: Number(cell) === 1 ? Check : Minus })) : null }));
    }
    renderLegend(legend, marker) {
        return (_jsx("div", { className: b('legend'), children: legend.map((item, index) => (_jsxs("div", { className: b('legend-item'), children: [this.renderMarker(marker, String(index)), _jsx(YFMWrapper, { className: b('legent-item-text'), content: item, modifiers: { constructor: true }, id: getMarkerId(index) })] }, item))) }));
    }
    getDefaultJustify(content, justify) {
        return justify || new Array(content[0].length).fill('center');
    }
}
//# sourceMappingURL=Table.js.map
