"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestedBars = void 0;
const react_1 = __importStar(require("react"));
const inlines_1 = require("inlines");
const varsUtilities_1 = require("../../varsUtilities");
const NestedOverlayLabels_1 = require("./NestedOverlayLabels");
const NestedBars = ({ value, largestValue, valueFormat, label, spacing = 0, barWidth = 26, direction, }) => {
    const [showLabel, setShowLabel] = (0, react_1.useState)(false);
    const [xPos, setXPos] = (0, react_1.useState)(0);
    const [yPos, setYPos] = (0, react_1.useState)(0);
    const [objKey, setObjKey] = (0, react_1.useState)('');
    const [objValue, setObjValue] = (0, react_1.useState)('');
    let valKeys = Object.keys(value);
    let sortable = [];
    for (const x in value) {
        sortable.push([x, value[x]]);
    }
    sortable.sort(function (a, b) {
        return b[1] - a[1];
    });
    return (react_1.default.createElement(inlines_1.styled.div, { style: {
            display: 'flex',
            flexDirection: direction === 'vertical' ? 'column-reverse' : 'row',
            marginBottom: direction !== 'vertical' && spacing,
            marginRight: direction === 'vertical' && spacing,
            minHeight: direction === 'vertical' ? 400 : 'auto',
        } },
        showLabel && (react_1.default.createElement(NestedOverlayLabels_1.NestedOverlayLabels, { xPos: xPos, yPos: yPos, objKey: objKey, objValue: objValue, valueFormat: valueFormat, direction: direction, value: value, label: label })),
        sortable.map((item, idx) => (react_1.default.createElement(inlines_1.styled.div, { key: idx, style: {
                height: direction === 'vertical'
                    ? `${(value[item[0]] / largestValue) * 100}%`
                    : barWidth,
                backgroundColor: (0, varsUtilities_1.color)('nonSemanticBackground', (0, varsUtilities_1.colorHash)('nonSemanticBackground', item[0]), 'strong'),
                // borderTopRightRadius: idx === valKeys.length - 1 ? 4 : 0,
                // borderBottomRightRadius: idx === valKeys.length - 1 ? 4 : 0,
                borderTopRightRadius: idx === valKeys.length - 1 && 4,
                borderTopLeftRadius: direction === 'vertical' && idx === valKeys.length - 1 ? 4 : 0,
                borderBottomRightRadius: direction === 'vertical' ? 0 : idx === valKeys.length - 1 ? 4 : 0,
                borderBottomLeftRadius: 0,
                width: direction === 'vertical'
                    ? barWidth
                    : `${(value[item[0]] / largestValue) * 100}%`,
                '&:hover': {
                    backgroundColor: (0, varsUtilities_1.color)('nonSemanticBackground', (0, varsUtilities_1.colorHash)('nonSemanticBackground', item[0]), 'soft'),
                },
            }, onMouseEnter: () => {
                setShowLabel(true);
                setObjKey(item[0]);
                setObjValue(value[item[0]]);
            }, onMouseLeave: () => setShowLabel(false), onMouseMove: (e) => {
                setYPos(e.clientY + 12);
                setXPos(e.clientX + 12);
            } })))));
};
exports.NestedBars = NestedBars;
//# sourceMappingURL=NestedBars.js.map