'use strict';

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

var iconsReact = require('@cloudtower/icons-react');
var index$1 = require('../Icon/index.js');
var styled = require('./styled.js');
var index = require('../Overflow/index.js');
var index$2 = require('../Truncate/index.js');
var antd = require('antd');
var cs = require('classnames');
var React = require('react');
var Antd5Dropdown = require('../Antd5Dropdown/Antd5Dropdown.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var cs__default = /*#__PURE__*/_interopDefault(cs);
var React__default = /*#__PURE__*/_interopDefault(React);

const LineChartColorBlock = ({ background, borderd = false }) => /* @__PURE__ */ React__default.default.createElement(
  "div",
  {
    className: cs__default.default(
      styled.LineChartColorBlockStyle,
      "color-block",
      borderd && "borderd"
    ),
    style: { background }
  }
);
const LineChartLegend = (props) => {
  const { deselected, onClick, legends, onHover, hovering, hovereringSelf } = props;
  const [isDropdownOpen, setIsDropdownOpen] = React__default.default.useState(false);
  return /* @__PURE__ */ React__default.default.createElement(
    index.ExtraOverflow,
    {
      className: styled.LegendStyle,
      extraEl: (end) => /* @__PURE__ */ React__default.default.createElement(
        Antd5Dropdown.Antd5Dropdown,
        {
          overlayClassName: styled.ExtraResource,
          trigger: ["click"],
          onVisibleChange: setIsDropdownOpen,
          overlay: /* @__PURE__ */ React__default.default.createElement(antd.Menu, null, legends.slice(end).map((legend, idx) => {
            return /* @__PURE__ */ React__default.default.createElement(
              antd.Menu.Item,
              {
                className: cs__default.default(
                  styled.LegendItemsStyleDropdown,
                  deselected.includes(legend.id) && "deselected",
                  hovering.includes(legend.id) && "hovering",
                  hovereringSelf.includes(legend.id) && "hoverering-self"
                ),
                key: legend.id,
                onClick: () => onClick(legend.id),
                onMouseEnter: () => onHover("enter", legend.id),
                onMouseLeave: () => onHover("leave", legend.id)
              },
              /* @__PURE__ */ React__default.default.createElement(LineChartColorBlock, { background: legend.color }),
              /* @__PURE__ */ React__default.default.createElement("span", { className: "legend-name" }, legend.name)
            );
          }))
        },
        /* @__PURE__ */ React__default.default.createElement(
          index$1,
          {
            alt: "arrowChevronDownSmall16Secondary",
            className: "dropdown-trigger",
            src: iconsReact.ArrowChevronDown16SecondaryIcon,
            hoverSrc: iconsReact.ArrowChevronDown16BlueIcon,
            activeSrc: iconsReact.ArrowChevronUp16BlueIcon,
            active: isDropdownOpen
          }
        )
      ),
      els: legends.map((legend) => {
        return /* @__PURE__ */ React__default.default.createElement(
          "div",
          {
            className: cs__default.default(
              styled.LegendItemsStyle,
              deselected.includes(legend.id) && "deselected",
              hovering.includes(legend.id) && "hovering",
              hovereringSelf.includes(legend.id) && "hoverering-self"
            ),
            key: legend.id,
            onMouseEnter: () => onHover("enter", legend.id),
            onMouseLeave: () => onHover("leave", legend.id),
            onClick: () => onClick(legend.id)
          },
          /* @__PURE__ */ React__default.default.createElement(LineChartColorBlock, { background: legend.color }),
          /* @__PURE__ */ React__default.default.createElement("span", { className: "legend-name" }, /* @__PURE__ */ React__default.default.createElement(index$2, { text: legend.name, len: 50, backLen: 20 }))
        );
      })
    }
  );
};
var LineChartLegend$1 = LineChartLegend;

exports.LineChartColorBlock = LineChartColorBlock;
exports.default = LineChartLegend$1;
