"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ChartLegendItem = ChartLegendItem;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _tooltip = require("../tooltip");
var _chartLegendItemGlyph = require("./chart-legend-item-glyph");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function ChartLegendItem({
  item,
  isInteractive = false,
  onChange = () => {},
  onMouseEnter = () => {},
  onMouseLeave = () => {}
}) {
  const {
    key,
    label,
    color,
    className,
    isActive,
    glyphType = _chartLegendItemGlyph.CHART_LEGEND_ITEM_GLYPH_TYPES.DISC,
    testId = 'chart-legend-item',
    tooltipText = '',
    isDisabled
  } = item;
  const id = `legend-item-${key}`;
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    className: (0, _classnames.default)('chart-legend-item', className),
    "test-id": testId,
    onMouseEnter: () => onMouseEnter({
      item
    }),
    onMouseLeave: () => onMouseLeave({
      item
    }),
    children: [isInteractive ? /*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
      onChange: e => isDisabled ? null : onChange({
        item,
        isActive: e.target.checked
      }),
      id: id,
      "test-id": "chart-legend-item-input",
      type: "checkbox",
      checked: isActive,
      value: key,
      className: "chart-legend-item-checkbox",
      disabled: isDisabled
    }) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_tooltip.Tooltip, {
      content: tooltipText,
      placement: _tooltip.TOOLTIP_PLACEMENT_TYPES.TOP,
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
        htmlFor: id,
        className: "chart-legend-item-label",
        "aria-labelledby": `${id}-glyph ${id}-label`,
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
          id: `${id}-glyph`,
          className: "chart-legend-glyph-wrapper",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_chartLegendItemGlyph.ChartLegendItemGlyph, {
            glyphType: glyphType,
            color: color
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
          id: `${id}-label`,
          children: label
        })]
      })
    })]
  });
}