"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
    for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
    for (var r = Array(s), k = 0, i = 0; i < il; i++)
        for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
            r[k] = a[j];
    return r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagsFilters = void 0;
var react_1 = __importStar(require("react"));
var _ = __importStar(require("lodash"));
var useMemoImmer_1 = require("../../../hooks/useMemoImmer");
var TagsFilters_utils_1 = require("../TagsFilters.utils");
var TagsFilters_style_1 = require("./TagsFilters.style");
exports.TagsFilters = react_1.default.forwardRef(function TagsFilters(_a, ref) {
    var filters = _a.filters, filtersSchema = _a.filtersSchema, removeTag = _a.removeTag;
    var tags = useMemoImmer_1.useMemoImmer(function () { return TagsFilters_utils_1.generateTagsFilters(filters, filtersSchema); }, [filters, filtersSchema]);
    react_1.useImperativeHandle(ref, function () { return ({
        tagsCount: tags.length,
    }); }, [tags]);
    var setEmptyField = react_1.useCallback(function setEmptyField(tag) {
        switch (tag.type) {
            case 'checkbox':
                removeTag(tag.key, _.remove(__spreadArrays(tag.values), function (n) { return n !== tag.checkboxValue; }));
                break;
            case 'location':
                removeTag(tag.key, tag.values
                    .split('_')
                    .filter(function (l) { return l !== tag.locationValue; })
                    .join('_'));
                break;
            case 'select':
            case 'input':
                removeTag(tag.key, tag.default);
                break;
        }
    }, []);
    return (react_1.default.createElement(TagsFilters_style_1.TagsFiltersStyle, null, !!tags.length && (react_1.default.createElement("div", { className: "tag-filters", "data-cy": "tag-filters" },
        react_1.default.createElement("div", { className: "search-tags" }, tags.map(function (tag, index) { return (react_1.default.createElement(TagFilter, { key: "tag-" + index, setEmptyField: setEmptyField, tag: tag })); }))))));
});
function TagFilter(_a) {
    var tag = _a.tag, setEmptyField = _a.setEmptyField;
    return (react_1.default.createElement("div", { className: "tag", onClick: function () { return setEmptyField(tag); }, "data-cy": "tag-" + tag.value, "data-testid": "tag-" + tag.value },
        react_1.default.createElement("span", null,
            react_1.default.createElement("b", null, tag.prefix),
            tag.value,
            tag.suffix)));
}
//# sourceMappingURL=TagsFilters.js.map