"use strict";

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

exports.__esModule = true;
exports["default"] = void 0;

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

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

var _classnames = _interopRequireDefault(require("classnames"));

var _lodash = require("lodash");

var _title = require("../title");

var _singleSelect = _interopRequireDefault(require("../single-select"));

var _context = _interopRequireDefault(require("../context"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * 筛选按钮
 * @param props IProps
 */
var FilterButton = function FilterButton(props) {
  var _useContext = (0, _react.useContext)(_context["default"]),
      _cssPrefix = _useContext._cssPrefix;

  var className = props.className,
      _props$dataSource = props.dataSource,
      dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
      _props$direction = props.direction,
      direction = _props$direction === void 0 ? 'row' : _props$direction,
      _props$align = props.align,
      align = _props$align === void 0 ? 'middle' : _props$align;
  var options = (0, _extends2["default"])({}, props);
  delete options.dataSource;
  return /*#__PURE__*/_react["default"].createElement(_singleSelect["default"], (0, _extends2["default"])({}, options, {
    className: (0, _classnames["default"])(_cssPrefix + "filter-button-wrapper", _cssPrefix + "filter-button-" + direction + "-" + align, className) // @ts-ignore
    ,
    style: _title.FLEX_STYLE[direction][align]
  }), dataSource.map(function (item, index) {
    var label = typeof item === 'object' ? item.label : item;
    var key = typeof item === 'object' ? item.value || index : item;
    return /*#__PURE__*/_react["default"].createElement(_singleSelect["default"].Item, {
      key: key,
      className: _cssPrefix + "filter-button",
      textStyle: (0, _extends2["default"])({
        fontWeight: 400,
        fontFamily: 'PingFang SC, Microsoft YaHei, serif'
      }, (0, _lodash.get)(props, 'textStyle', {}))
    }, label);
  }));
};

var _default = FilterButton;
exports["default"] = _default;