"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BarLegend = void 0;
const react_1 = __importDefault(require("react"));
const inlines_1 = require("inlines");
const Text_1 = require("../../components/Text");
const varsUtilities_1 = require("../../varsUtilities");
const pretty_number_1 = require("@based/pretty-number");
const BarLegend = ({ data, direction = 'horizontal', valueFormat = 'number-short', nested, stacked, }) => {
    if (nested || stacked) {
        const nestedDataKeysArr = [];
        let flatArr;
        if (nested || stacked) {
            for (let i = 0; i < data.length; i++) {
                let arr = Object.keys(data[i].value);
                nestedDataKeysArr.push(arr);
            }
        }
        //flatten array
        let tempData = [];
        flatArr = [...nestedDataKeysArr.flat()];
        const dataSet = new Set(flatArr);
        Array.from(dataSet).map((item) => tempData.push({ label: item }));
        data = [...tempData];
    }
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            display: 'flex',
            gap: direction === 'vertical' && !nested && !stacked ? 4 : 20,
            justifyContent: 'center',
            flexDirection: direction === 'vertical' && !nested && !stacked ? 'column' : 'row',
            marginTop: 24,
        } }, data.map((item, idx) => (react_1.default.createElement(inlines_1.styled.div, { style: { display: 'flex', gap: 6, alignItems: 'center' }, key: idx },
        react_1.default.createElement(inlines_1.styled.div, { style: {
                width: 12,
                height: 12,
                borderRadius: 6,
                backgroundColor: item.color
                    ? (0, varsUtilities_1.color)('nonSemanticBackground', item.color || 'magenta', 'muted')
                    : (0, varsUtilities_1.color)('nonSemanticBackground', (0, varsUtilities_1.colorHash)('nonSemanticBackground', item.label), 'strong'),
            } }),
        react_1.default.createElement(Text_1.Text, { size: 12, weight: "medium", truncate: true },
            item.label,
            ' '),
        !nested && !stacked && (react_1.default.createElement(Text_1.Text, { weight: "strong" },
            ' ',
            direction === 'vertical' && valueFormat
                ? (0, pretty_number_1.prettyNumber)(item.value, valueFormat)
                : direction === 'vertical' && item.percentage.toFixed(1) + '%')))))));
};
exports.BarLegend = BarLegend;
//# sourceMappingURL=BarLegend.js.map