import React from "react";
const get = (obj, property) => (typeof obj === "object" ? obj[property] : obj);
export const check = (obj, property) => typeof obj === "object" && typeof obj[property] === "number"
    ? obj[property].toLocaleString()
    : typeof obj === "object"
        ? obj[property]
        : false;
export const FacetSelect = ({ items, className, selected, label, setSelected, }) => {
    const setSelectorNoPropagation = (e, value) => {
        e.stopPropagation();
        setSelected(value);
    };
    return (React.createElement("div", { className: className },
        label && React.createElement("h2", null, label),
        React.createElement("div", { className: "facet-list" },
            React.createElement("ul", { className: "level-1" }, items.map((item, index) => (React.createElement("li", { key: index, onClick: (e) => setSelectorNoPropagation(e, get(item, "value")), className: selected && selected == get(item, "value")
                    ? "selected-facet facet"
                    : "facet" },
                React.createElement("span", { className: "label" },
                    get(item, "label"),
                    check(item, "count") && React.createElement("span", null,
                        "(",
                        check(item, "count"),
                        ")")),
                check(item, "children") && (React.createElement("ul", { className: "level-2" }, get(item, "children").map((item, index) => (React.createElement("li", { key: index, onClick: (e) => setSelectorNoPropagation(e, item.value), className: selected && selected == item.value
                        ? "selected-facet facet"
                        : "facet" },
                    React.createElement("span", { className: "label" },
                        item.label,
                        item.count && React.createElement("span", null,
                            "(",
                            item.count,
                            ")"))))))))))))));
};
