"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.FilterChip = void 0;
var _classnames = _interopRequireDefault(require("classnames"));
var _useId = _interopRequireDefault(require("../utilities/useId"));
var _Icons = require("../Icons");
var _i18n = require("../i18n");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const 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/).
 */
const FilterChip = _ref => {
  let {
    ariaClearLabel,
    className,
    label,
    id,
    onDelete,
    size,
    useAlternateIcon
  } = _ref;
  const filterChipId = (0, _useId.default)('filter-chip--', id);
  function handleClick() {
    onDelete();
  }
  function handleKeyDown(evt) {
    if (actionableKeys.includes(evt.key)) {
      handleClick();
      evt.preventDefault();
    }
  }
  const buttonClassNames = (0, _classnames.default)('ds-c-filter-chip__button', size && size === 'big' ? 'ds-c-filter-chip__button--big' : '', className);
  const iconContainerClassNames = (0, _classnames.default)('ds-c-filter-chip__clear-icon-container', useAlternateIcon ? 'ds-c-filter-chip__clear-icon-alternate-container' : '');
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("button", {
    id: filterChipId,
    className: buttonClassNames,
    onClick: handleClick,
    onKeyDown: handleKeyDown,
    type: "button",
    children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: "ds-c-filter-chip__label",
      "aria-hidden": true,
      "aria-describedby": `${filterChipId}-instructions`,
      children: label
    }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
      id: `${filterChipId}-instructions`,
      className: "ds-u-visibility--screen-reader",
      children: [ariaClearLabel ?? (0, _i18n.t)('filterChip.ariaClearLabel'), " ", (0, _i18n.t)('filterChip.filter', {
        label
      }), " ."]
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
      className: iconContainerClassNames,
      children: useAlternateIcon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icons.CloseIconThin, {}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icons.CloseIcon, {})
    })]
  });
};
exports.FilterChip = FilterChip;
var _default = exports.default = FilterChip;