"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.TokenFilterChips = TokenFilterChips;
const react_1 = __importStar(require("react"));
const aksel_icons_1 = require("@navikt/aksel-icons");
const action_menu_1 = require("../../action-menu");
const popover_1 = require("../../popover");
function TokenFilterChips(props) {
    const { tokens, removeToken, operation, updateOperation } = props;
    if (tokens.length === 0) {
        return null;
    }
    return (react_1.default.createElement("ul", { className: "aksel-property-filter__chips" }, tokens.map((token, index) => (react_1.default.createElement(TokenFilterChip, { key: index, onRemove: () => removeToken(index), token: token, showOperation: index > 0, operation: operation, updateOperation: updateOperation })))));
}
function TokenFilterChip(props) {
    const { token, onRemove, showOperation, operation } = props;
    const [popupAnchor, setPopupAnchor] = (0, react_1.useState)(null);
    const [isPopupOpen, setIsPopupOpen] = (0, react_1.useState)(false);
    return (react_1.default.createElement("li", { className: "aksel-property-filter__chip" },
        showOperation && (react_1.default.createElement(action_menu_1.ActionMenu, null,
            react_1.default.createElement(action_menu_1.ActionMenu.Trigger, null,
                react_1.default.createElement("button", { className: "aksel-property-filter__chip-button", "data-type": "operation" }, operation === "and" ? "og" : "eller")),
            react_1.default.createElement(action_menu_1.ActionMenu.Content, null,
                react_1.default.createElement(action_menu_1.ActionMenu.Item, { onSelect: () => { var _a; return (_a = props.updateOperation) === null || _a === void 0 ? void 0 : _a.call(props, "and"); } }, "AND"),
                react_1.default.createElement(action_menu_1.ActionMenu.Item, { onSelect: () => { var _a; return (_a = props.updateOperation) === null || _a === void 0 ? void 0 : _a.call(props, "or"); } }, "OR")))),
        react_1.default.createElement("button", { "data-type": "value", className: "aksel-property-filter__chip-button", ref: setPopupAnchor, onClick: () => setIsPopupOpen((open) => !open) }, `${token.propertyKey} ${token.operator} ${token.value}`),
        react_1.default.createElement(popover_1.Popover, { open: isPopupOpen, onClose: () => setIsPopupOpen(false), anchorEl: popupAnchor, placement: "bottom-start" },
            react_1.default.createElement(popover_1.Popover.Content, null, "Edit filter")),
        react_1.default.createElement("button", { "data-type": "remove", className: "aksel-property-filter__chip-button", onClick: onRemove },
            react_1.default.createElement(aksel_icons_1.XMarkIcon, { "aria-hidden": true, fontSize: "1.25rem" }))));
}
//# sourceMappingURL=FilterChip.js.map