"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
    for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
        to[j] = from[i];
    return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TagsFilters = void 0;
var react_1 = __importStar(require("react"));
var react_hooks_1 = require("@devesharp/react-hooks");
var _ = __importStar(require("lodash"));
var TagsFilters_interface_1 = require("./TagsFilters.interface");
var TagsFilters_style_1 = require("./TagsFilters.style");
var TagsFilters_utils_1 = require("./TagsFilters.utils");
exports.TagsFilters = react_1.default.forwardRef(function TagsFilters(_a, ref) {
    var filters = _a.filters, filtersSchema = _a.filtersSchema, removeTag = _a.removeTag, fullColor = _a.fullColor;
    var tags = react_hooks_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) {
        var _a;
        switch (tag.type) {
            case 'checkbox':
                removeTag(tag.key, _.remove(__spreadArray([], tag.values), function (n) { return n !== tag.checkboxValue; }));
                break;
            case TagsFilters_interface_1.ETagFilterType.CheckBoxKey:
                removeTag(tag.key, __assign(__assign({}, tag.values), (_a = {}, _a[tag.checkboxValue] = false, _a)));
                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;
        }
    }, [removeTag]);
    return (react_1.default.createElement(TagsFilters_style_1.TagsFiltersStyle, { fullColor: fullColor }, !!tags.length && (react_1.default.createElement("div", { className: "tag-filters", "data-testid": "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-testid": "tag-" + tag.value },
        react_1.default.createElement("span", null,
            tag.prefix,
            tag.value,
            tag.suffix)));
}
//# sourceMappingURL=TagsFilters.js.map