Liferay.Loader.define("dynamic-data-mapping-form-report-web@1.0.29/js/components/chart/Legend.es", ['module', 'exports', 'require', '@frontend-taglib-clay$clayui/button', '@frontend-taglib-clay$clayui/icon', 'frontend-js-react-web$react', '../../utils/colors.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    function _typeof(obj) {
      "@babel/helpers - typeof";
      if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
        _typeof = function _typeof(obj) {
          return typeof obj;
        };
      } else {
        _typeof = function _typeof(obj) {
          return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
        };
      }return _typeof(obj);
    }

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.default = void 0;

    var _button = _interopRequireDefault(require("@frontend-taglib-clay$clayui/button"));

    var _icon = _interopRequireDefault(require("@frontend-taglib-clay$clayui/icon"));

    var _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _colors = _interopRequireDefault(require("../../utils/colors.es"));

    function _getRequireWildcardCache() {
      if (typeof WeakMap !== "function") return null;var cache = new WeakMap();_getRequireWildcardCache = function _getRequireWildcardCache() {
        return cache;
      };return cache;
    }

    function _interopRequireWildcard(obj) {
      if (obj && obj.__esModule) {
        return obj;
      }if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") {
        return { default: obj };
      }var cache = _getRequireWildcardCache();if (cache && cache.has(obj)) {
        return cache.get(obj);
      }var newObj = {};var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;for (var key in obj) {
        if (Object.prototype.hasOwnProperty.call(obj, key)) {
          var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;if (desc && (desc.get || desc.set)) {
            Object.defineProperty(newObj, key, desc);
          } else {
            newObj[key] = obj[key];
          }
        }
      }newObj.default = obj;if (cache) {
        cache.set(obj, newObj);
      }return newObj;
    }

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { default: obj };
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    var MAX_LABELS = 10;

    var Label = function Label(_ref) {
      var active = _ref.active,
          color = _ref.color,
          index = _ref.index,
          label = _ref.label,
          onMouseOut = _ref.onMouseOut,
          onMouseOver = _ref.onMouseOver;
      return (/*#__PURE__*/_react.default.createElement("li", {
          className: active ? '' : 'dim',
          "data-item": index
        }, /*#__PURE__*/_react.default.createElement("svg", {
          height: "20",
          width: "20"
        }, /*#__PURE__*/_react.default.createElement("circle", {
          cx: "10",
          cy: "10",
          fill: color,
          onMouseOut: onMouseOut,
          onMouseOver: onMouseOver,
          r: "9",
          strokeWidth: "3"
        })), /*#__PURE__*/_react.default.createElement("p", {
          onMouseOut: onMouseOut,
          onMouseOver: onMouseOver,
          x: "0em",
          y: "1em"
        }, /*#__PURE__*/_react.default.createElement("span", {
          dy: "2em",
          x: "2.5em"
        }, label)))
      );
    };

    var ShowAll = function ShowAll(_ref2) {
      var expand = _ref2.expand,
          expanded = _ref2.expanded,
          labelsLength = _ref2.labelsLength;

      if (labelsLength <= MAX_LABELS) {
        return null;
      }

      var toggleExpanded = function toggleExpanded() {
        expand(!expanded);
      };

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "show-more-action"
        }, /*#__PURE__*/_react.default.createElement("svg", {
          height: "20",
          width: "20"
        }, /*#__PURE__*/_react.default.createElement("g", null, /*#__PURE__*/_react.default.createElement("circle", {
          cx: "10",
          cy: "10",
          fill: '#F0F5FF',
          r: "9",
          strokeWidth: "3"
        }), /*#__PURE__*/_react.default.createElement(_icon.default, {
          symbol: expanded ? 'caret-top-l' : 'caret-bottom-l'
        }))), /*#__PURE__*/_react.default.createElement(_button.default, {
          className: "show-more-button",
          displayType: "unstyled",
          onClick: function onClick() {
            return toggleExpanded();
          }
        }, expanded ? Liferay.Language.get('show-less') : Liferay.Language.get('show-all')))
      );
    };

    var _default = function _default(_ref3) {
      var activeIndex = _ref3.activeIndex,
          labels = _ref3.labels,
          onMouseOut = _ref3.onMouseOut,
          onMouseOver = _ref3.onMouseOver;

      var _useState = (0, _react.useState)(false),
          _useState2 = _slicedToArray(_useState, 2),
          isShowAllExpanded = _useState2[0],
          expandShowAll = _useState2[1];

      var handleOnMouseOver = function handleOnMouseOver(_ref4) {
        var currentTarget = _ref4.currentTarget;
        var item = currentTarget.closest('li').dataset.item;
        onMouseOver(parseInt(item, 10));
      };

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "legend-container well well-lg"
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "legend-list"
        }, /*#__PURE__*/_react.default.createElement("ul", null, labels.slice(0, isShowAllExpanded ? labels.length : MAX_LABELS).map(function (label, index) {
          return (/*#__PURE__*/_react.default.createElement(Label, {
              active: activeIndex === null || activeIndex === index,
              color: (0, _colors.default)(index),
              index: index,
              key: "item-".concat(index),
              label: label,
              onMouseOut: onMouseOut,
              onMouseOver: handleOnMouseOver
            })
          );
        }), /*#__PURE__*/_react.default.createElement(ShowAll, {
          expand: expandShowAll,
          expanded: isShowAllExpanded,
          labelsLength: labels.length
        }))))
      );
    };

    exports.default = _default;
    //# sourceMappingURL=Legend.es.js.map
  }
});
//# sourceMappingURL=Legend.es.js.map