"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.useTagsFilter = exports.extractTagsFilter = exports.buildTagsFilterElement = void 0;
var _useSelector = require("../../useSelector");
var _TagsFilter = require("./TagsFilter");
var _react = _interopRequireDefault(require("react"));
var _jsxFileName = "/home/builduser/work/843658b9f44192f0/packages/cairo/dist/cjs/components/TagsFilter/tagsFilterBuilder.tsx";
const buildTagsFilterElement = state => {
  var _state$collection$fil;
  const label = state.container.translate('cairo.tags.filterPanel.dropdown.title');
  return /*#__PURE__*/_react.default.createElement(_TagsFilter.TagsFilter, {
    key: (_state$collection$fil = state.collection.filters.tags) == null ? void 0 : _state$collection$fil.name,
    filter: state.collection.filters.tags,
    accordionItemProps: {
      label
    },
    toolbarItemProps: {
      label
    },
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 16,
      columnNumber: 5
    }
  });
};
exports.buildTagsFilterElement = buildTagsFilterElement;
const useTagsFilter = state => {
  (0, _useSelector.useSelector)(() => state.toolbar.collection.filters.tags);
  const buildTagsFilterWrapper = () => {
    return buildTagsFilterElement(state.toolbar);
  };
  return {
    buildTagsFilter: buildTagsFilterWrapper
  };
};
exports.useTagsFilter = useTagsFilter;
const extractTagsFilter = (filters, key = 'tags.privateTags.tagIds') => {
  const tagsFilterValue = filters.tags;
  if (!(tagsFilterValue != null && tagsFilterValue.length)) {
    return {};
  }
  const tagIds = tagsFilterValue.map(tag => tag.id);
  return {
    [key]: tagIds
  };
};
exports.extractTagsFilter = extractTagsFilter;
//# sourceMappingURL=tagsFilterBuilder.js.map