"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.CheckboxList = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

var _react = _interopRequireDefault(require("react"));

var _lib = require("@sentecacommerce-theme/lib");

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _Common = require("../../../../../Common");

var _templateObject, _templateObject2, _templateObject3;

var labelGettersMap = {
  terms: _lib.getTermsAggregationLabel,
  ranges: function ranges(filter) {
    if (filter.data.from === '*') {
      return "\u043F\u043E\u0434 " + filter.data.to / 100 + "\u043B\u0432";
    }

    if (filter.data.to === '*') {
      return "\u043D\u0430\u0434 " + filter.data.from / 100 + "\u043B\u0432";
    }

    return filter.data.from / 100 + "\u043B\u0432 - " + filter.data.to / 100 + "\u043B\u0432";
  }
};

var CheckboxList = function CheckboxList(_ref) {
  var type = _ref.type,
      items = _ref.items,
      _onChange = _ref.onChange;
  return /*#__PURE__*/_react["default"].createElement(Row, null, items.map(function (filter, i) {
    var _labelGettersMap$type;

    var label = ((_labelGettersMap$type = labelGettersMap[type]) == null ? void 0 : _labelGettersMap$type.call(labelGettersMap, filter)) || null;
    var count = filter.data.count;
    return /*#__PURE__*/_react["default"].createElement(Wrapper, {
      key: "Filter__" + label + "--" + i
    }, /*#__PURE__*/_react["default"].createElement(_Common.Checkbox, {
      onChange: function onChange() {
        _onChange == null ? void 0 : _onChange();
        filter.onClick();
      },
      isChecked: filter.selected,
      label: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, label, Boolean(count) && /*#__PURE__*/_react["default"].createElement(Count, null, count)),
      size: "tiny"
    }));
  }));
};

exports.CheckboxList = CheckboxList;

var Row = _styledComponents["default"].div.attrs({
  className: 'row row-cols-1 row-cols-md-1'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var Wrapper = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  @media (max-width: ", ") {\n    margin-bottom: 0.8rem;\n\n    &:last-of-type {\n      margin-bottom: 0;\n    }\n  }\n"])), function (_ref2) {
  var theme = _ref2.theme;
  return theme.breakpoints.sm.max;
});

var Count = _styledComponents["default"].span.attrs({
  className: 'd-flex align-items-center justify-content-center ml-2 px-2'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  min-width: 2.6rem;\n  height: 2rem;\n  font-size: 1rem;\n  color: ", ";\n  font-weight: bold;\n  background-color: ", ";\n  border-radius: 4rem;\n"])), function (_ref3) {
  var theme = _ref3.theme;
  return theme.palette.primary;
}, function (_ref4) {
  var theme = _ref4.theme;
  return theme.palette.light;
});
//# sourceMappingURL=index.js.map