"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.FilterChip = void 0;
var _compat = _interopRequireDefault(require("preact/compat"));
var _classnames = _interopRequireDefault(require("classnames"));
var _useId = _interopRequireDefault(require("../utilities/useId"));
var _Icons = require("../Icons");
var _i18n = require("../i18n");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var actionableKeys = ['Enter', 'Space', 'Backspace', 'Delete'];
/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/filter-chip/).
 */
var FilterChip = function FilterChip(_ref) {
  var ariaClearLabel = _ref.ariaClearLabel,
    className = _ref.className,
    label = _ref.label,
    id = _ref.id,
    onDelete = _ref.onDelete,
    size = _ref.size,
    useAlternateIcon = _ref.useAlternateIcon;
  var filterChipId = (0, _useId.default)('filter-chip--', id);
  function handleClick() {
    onDelete();
  }
  function handleKeyDown(evt) {
    if (actionableKeys.includes(evt.key)) {
      handleClick();
      evt.preventDefault();
    }
  }
  var buttonClassNames = (0, _classnames.default)('ds-c-filter-chip__button', size && size === 'big' ? 'ds-c-filter-chip__button--big' : '', className);
  var iconContainerClassNames = (0, _classnames.default)('ds-c-filter-chip__clear-icon-container', useAlternateIcon ? 'ds-c-filter-chip__clear-icon-alternate-container' : '');
  return /*#__PURE__*/_compat.default.createElement("button", {
    id: filterChipId,
    className: buttonClassNames,
    onClick: handleClick,
    onKeyDown: handleKeyDown,
    type: "button"
  }, /*#__PURE__*/_compat.default.createElement("span", {
    className: "ds-c-filter-chip__label",
    "aria-hidden": true,
    "aria-describedby": "".concat(filterChipId, "-instructions")
  }, label), /*#__PURE__*/_compat.default.createElement("span", {
    id: "".concat(filterChipId, "-instructions"),
    className: "ds-u-visibility--screen-reader"
  }, ariaClearLabel !== null && ariaClearLabel !== void 0 ? ariaClearLabel : (0, _i18n.t)('filterChip.ariaClearLabel'), " ", (0, _i18n.t)('filterChip.filter', {
    label: label
  }), " ."), /*#__PURE__*/_compat.default.createElement("span", {
    className: iconContainerClassNames
  }, useAlternateIcon ? /*#__PURE__*/_compat.default.createElement(_Icons.CloseIconThin, null) : /*#__PURE__*/_compat.default.createElement(_Icons.CloseIcon, null)));
};
exports.FilterChip = FilterChip;
var _default = FilterChip;
exports.default = _default;