'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var clsx = require('clsx');
var React = require('react');
var Body = require('../body/Body.js');
require('../common/theme.js');
require('../common/direction.js');
require('../common/propsValues/control.js');
require('../common/propsValues/breakpoint.js');
require('../common/propsValues/size.js');
var typography = require('../common/propsValues/typography.js');
require('../common/propsValues/width.js');
require('../common/propsValues/type.js');
require('../common/propsValues/dateMode.js');
require('../common/propsValues/monthFormat.js');
require('../common/propsValues/position.js');
require('../common/propsValues/layouts.js');
require('../common/propsValues/status.js');
require('../common/propsValues/sentiment.js');
require('../common/propsValues/profileType.js');
require('../common/propsValues/variant.js');
require('../common/propsValues/scroll.js');
require('../common/propsValues/markdownNodeType.js');
require('../common/fileType.js');
var CloseButton = require('../common/closeButton/CloseButton.js');
var jsxRuntime = require('react/jsx-runtime');

const Chip = ({
  label,
  value,
  onRemove,
  onClick,
  onKeyPress,
  className = undefined,
  'aria-label': ariaLabel,
  'aria-checked': ariaChecked,
  role,
  closeButton
}) => {
  const isActionable = onClick || onKeyPress;
  const defaultRole = isActionable ? 'button' : undefined;
  const tabIndex = isActionable ? 0 : -1;
  const closeButtonReference = React.useRef(null);
  const previousCloseButtonShown = React.useRef(undefined);
  React.useEffect(() => {
    if (closeButtonReference.current != null && previousCloseButtonShown.current === false) {
      closeButtonReference.current?.focus();
    }
    previousCloseButtonShown.current = closeButtonReference.current != null;
  }, [onRemove]);
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    role: role ?? defaultRole,
    tabIndex: tabIndex,
    "aria-label": ariaLabel,
    "aria-checked": ariaChecked,
    className: clsx.clsx('np-chip', 'd-flex', 'align-items-center', 'justify-content-between', onRemove ? 'np-chip--removable' : '', className),
    ...(isActionable && {
      onClick,
      onKeyPress
    }),
    children: [/*#__PURE__*/jsxRuntime.jsx(Body.default, {
      "aria-hidden": !!onRemove,
      type: typography.Typography.BODY_DEFAULT_BOLD,
      children: label
    }), onRemove ? /*#__PURE__*/jsxRuntime.jsx(CloseButton.CloseButton, {
      ref: closeButtonReference,
      className: "btn-unstyled",
      "aria-label": closeButton?.['aria-label'],
      size: "sm",
      filled: true,
      onClick: onRemove
    }) : null]
  }, value);
};

exports.default = Chip;
//# sourceMappingURL=Chip.js.map
