"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SelectableTilesItem = SelectableTilesItem;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _fontAwesomeIcon = require("../font-awesome-icon");
var _tooltip = require("../tooltip");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function SelectableTilesItem({
  id,
  label,
  imgSrc,
  icon,
  itemTestId,
  size,
  selectedKey,
  onItemSelect,
  isDisabled,
  itemClassName,
  itemAriaLabel,
  customContent,
  tooltipText,
  tooltipPlacement = _tooltip.TOOLTIP_PLACEMENT_TYPES.RIGHT
}) {
  const isItemSelected = id === selectedKey;
  const handleClick = () => {
    if (!isDisabled) {
      onItemSelect?.(id);
    }
  };
  const handleKeyDown = event => {
    if (event.key === ' ' && !isDisabled) {
      event.preventDefault();
      onItemSelect?.(id);
    }
  };
  function renderContent() {
    if (customContent) {
      return customContent;
    }
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(StandardContent, {
      label: label,
      imgSrc: imgSrc,
      icon: icon
    });
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
    content: tooltipText,
    placement: tooltipPlacement,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: (0, _classnames.default)('selectable-tiles-item', itemClassName, size, {
        'selectable-tiles-item-selected': isItemSelected,
        'selectable-tiles-item-disabled': isDisabled,
        'label-with-image': !!imgSrc
      }),
      onClick: handleClick,
      onKeyDown: handleKeyDown,
      "test-id": itemTestId || 'selectable-tiles-item',
      role: "radio",
      "aria-label": itemAriaLabel,
      "aria-checked": isItemSelected,
      tabIndex: 0,
      children: renderContent()
    })
  });
}
function StandardContent({
  imgSrc,
  icon,
  label
}) {
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [imgSrc ? /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
      className: "selectable-tiles-item-image-container",
      "test-id": "selectable-tiles-item-image",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("img", {
        alt: label,
        src: imgSrc,
        className: "selectable-tiles-item-image"
      })
    }) : null, icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_fontAwesomeIcon.FontAwesomeIcon, {
      icon: icon,
      className: "selectable-tiles-item-icon",
      "test-id": "selectable-tiles-item-icon"
    }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
      className: "selectable-tiles-item-label",
      children: label
    })]
  });
}