"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FacetSelect = exports.check = void 0;
const react_1 = __importDefault(require("react"));
const get = (obj, property) => (typeof obj === 'object' ? obj[property] : obj);
const check = (obj, property) => typeof obj === 'object' && typeof obj[property] === 'number'
    ? obj[property].toLocaleString()
    : typeof obj === 'object'
        ? obj[property]
        : false;
exports.check = check;
const FacetSelect = ({ items, className, selected, label, setSelected, }) => {
    const setSelectorNoPropagation = (e, value) => {
        e.stopPropagation();
        setSelected(value);
    };
    return (react_1.default.createElement("div", { className: className },
        label && react_1.default.createElement("h2", null, label),
        react_1.default.createElement("div", { className: "facet-list" },
            react_1.default.createElement("ul", { className: "level-1" }, items.map((item, index) => (react_1.default.createElement("li", { key: index, onClick: e => setSelectorNoPropagation(e, get(item, 'value')), className: selected && selected == get(item, 'value')
                    ? 'selected-facet facet'
                    : 'facet' },
                react_1.default.createElement("span", { className: "label" },
                    get(item, 'label'),
                    (0, exports.check)(item, 'count') && react_1.default.createElement("span", null,
                        "(",
                        (0, exports.check)(item, 'count'),
                        ")")),
                (0, exports.check)(item, 'children') && (react_1.default.createElement("ul", { className: "level-2" }, get(item, 'children').map((item, index) => (react_1.default.createElement("li", { key: index, onClick: e => setSelectorNoPropagation(e, item.value), className: selected && selected == item.value
                        ? 'selected-facet facet'
                        : 'facet' },
                    react_1.default.createElement("span", { className: "label" },
                        item.label,
                        item.count && react_1.default.createElement("span", null,
                            "(",
                            item.count,
                            ")"))))))))))))));
};
exports.FacetSelect = FacetSelect;
