"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyValueIconSelector = exports.KeyValueValueSelector = exports.KeyValueKeySelector = exports.KeyValuePairSelector = exports.KeyValueItemSelector = exports.KeyValue = void 0;
const react_1 = __importStar(require("react"));
const KeyValue_styled_1 = require("./KeyValue.styled");
const DEFAULT_COLS = 2;
const KeyValue = (0, react_1.forwardRef)((props, ref) => {
    var _a;
    const cols = (_a = props.cols) !== null && _a !== void 0 ? _a : DEFAULT_COLS;
    const items = props.items.map((value, key) => {
        const width = `${100 / cols}%`;
        const style = { width };
        const isFirstRow = key < cols;
        const isFirstCol = (key % cols) === 0;
        const kvKey = value.key != null ? react_1.default.createElement(KeyValue_styled_1.Key, null, value.key) : null;
        const kvValue = value.value != null ? react_1.default.createElement(KeyValue_styled_1.Value, null, value.value) : null;
        const keyValue = (react_1.default.createElement(KeyValue_styled_1.KeyValuePair, null,
            props.valueFirst ? kvValue : kvKey,
            !props.valueFirst ? kvValue : kvKey));
        const icon = value.icon != null ? react_1.default.createElement(KeyValue_styled_1.Icon, null, value.icon) : null;
        const component = value.onClick ? "button" : "div";
        return react_1.default.createElement(KeyValue_styled_1.Item, {
            key,
            style,
            as: component,
            notFirstRow: !isFirstRow,
            notFirstCol: !isFirstCol,
        }, react_1.default.createElement(react_1.default.Fragment, null,
            icon,
            keyValue));
    });
    const rest = items.length % cols;
    const missingItems = rest ? cols - rest : 0;
    if (missingItems) {
        const width = `${(100 / cols) * (missingItems)}%`;
        const style = { width };
        const firstRow = items.length < cols;
        const firstCol = (items.length % cols) === 0;
        items.push(react_1.default.createElement(KeyValue_styled_1.Item, { key: "extra", css: style, notFirstCol: !firstCol, notFirstRow: !firstRow }));
    }
    return (react_1.default.createElement(KeyValue_styled_1.Container, { className: props.className, ref: ref }, items));
});
exports.KeyValue = KeyValue;
KeyValue.displayName = "KeyValue";
KeyValue.toString = () => KeyValue_styled_1.Container.toString();
const KeyValueItemSelector = KeyValue_styled_1.Item.toString();
exports.KeyValueItemSelector = KeyValueItemSelector;
const KeyValuePairSelector = KeyValue_styled_1.KeyValuePair.toString();
exports.KeyValuePairSelector = KeyValuePairSelector;
const KeyValueKeySelector = KeyValue_styled_1.Key.toString();
exports.KeyValueKeySelector = KeyValueKeySelector;
const KeyValueValueSelector = KeyValue_styled_1.Value.toString();
exports.KeyValueValueSelector = KeyValueValueSelector;
const KeyValueIconSelector = KeyValue_styled_1.Icon.toString();
exports.KeyValueIconSelector = KeyValueIconSelector;
//# sourceMappingURL=KeyValue.js.map