"use strict";

exports.__esModule = true;
exports.transformCustomFiltersToWQL = void 0;
var _transformCustomDateFilterToWQL = require("./transformCustomDateFilterToWQL");
var _transformCustomCheckboxToWQL = require("./transformCustomCheckboxToWQL");
var _transformCustomNumberRangeFilterToWQL = require("./transformCustomNumberRangeFilterToWQL");
var _simplifyExtendedColumns = require("../../state/simplifyExtendedColumns");
var _transformOperatorFilterToWQL = require("./transformOperatorFilterToWQL");
const transformCustomFiltersToWQL = (state, filters) => {
  const transformToWqlMapper = {
    date: _transformCustomDateFilterToWQL.transformCustomDateFilterToWQL,
    dateTime: _transformCustomDateFilterToWQL.transformCustomDateFilterToWQL,
    checkbox: _transformCustomCheckboxToWQL.transformCustomCheckboxToWQL,
    decimal: _transformCustomNumberRangeFilterToWQL.transformCustomNumberRangeFilterToWQL,
    integer: _transformCustomNumberRangeFilterToWQL.transformCustomNumberRangeFilterToWQL,
    shortText: _transformOperatorFilterToWQL.transformOperatorFilterToWQL,
    longText: _transformOperatorFilterToWQL.transformOperatorFilterToWQL,
    url: _transformOperatorFilterToWQL.transformOperatorFilterToWQL
  };
  const platformizedFilters = Object.keys(filters).reduce((acc, filterId) => {
    var _state$toolbar$collec;
    const filterValue = filters[filterId];
    const currCustomField = (_state$toolbar$collec = state.toolbar.collectionDataExtension) == null ? void 0 : _state$toolbar$collec.dataExtension.filterableCustomFields.find(field => field.id === filterId);
    if (!currCustomField || filterValue == null) {
      return acc;
    }
    const filterName = (0, _simplifyExtendedColumns.prefixFieldWithNamespace)(currCustomField.id, currCustomField.namespace);
    const transformToWql = transformToWqlMapper[currCustomField.type];
    if (!transformToWql) {
      return acc;
    }
    acc.push(...transformToWql(filterName, filterValue));
    return acc;
  }, []);
  return {
    $and: platformizedFilters
  };
};
exports.transformCustomFiltersToWQL = transformCustomFiltersToWQL;
//# sourceMappingURL=transformCustomFiltersToWQL.js.map