Liferay.Loader.define("dynamic-data-mapping-form-report-web@1.0.29/js/components/chart/bar/SimpleBarChart.es", ['module', 'exports', 'require', 'frontend-js-react-web$react', 'frontend-js-recharts$recharts', '../../../utils/colors.es', '../../../utils/ellipsize.es', '../TooltipContent.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 _react = _interopRequireWildcard(require("frontend-js-react-web$react"));

    var _recharts = require("frontend-js-recharts$recharts");

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

    var _ellipsize = _interopRequireDefault(require("../../../utils/ellipsize.es"));

    var _TooltipContent = _interopRequireDefault(require("../TooltipContent.es"));

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

    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 _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 blueDark = _colors.NAMED_COLORS.blueDark,
        gray = _colors.NAMED_COLORS.gray,
        lightBlue = _colors.NAMED_COLORS.lightBlue,
        white = _colors.NAMED_COLORS.white;

    var _default = function _default(_ref) {
      var data = _ref.data,
          height = _ref.height,
          totalEntries = _ref.totalEntries,
          width = _ref.width;

      var _useState = (0, _react.useState)(null),
          _useState2 = _slicedToArray(_useState, 2),
          activeIndex = _useState2[0],
          setActiveIndex = _useState2[1];

      var handleOnMouseOver = function handleOnMouseOver(index) {
        setActiveIndex(index);
      };

      return (/*#__PURE__*/_react.default.createElement("div", {
          className: "custom-chart-size simple-bar-chart"
        }, /*#__PURE__*/_react.default.createElement(_recharts.ResponsiveContainer, {
          height: height || '99%',
          width: width || '99%'
        }, /*#__PURE__*/_react.default.createElement(_recharts.BarChart, {
          data: data,
          layout: "vertical",
          margin: {
            bottom: 20,
            left: 20,
            right: 20,
            top: 20
          }
        }, /*#__PURE__*/_react.default.createElement(_recharts.XAxis, {
          axisLine: {
            stroke: gray
          },
          tick: {
            fontSize: 14
          },
          tickLine: false,
          type: "number"
        }), /*#__PURE__*/_react.default.createElement(_recharts.YAxis, {
          dataKey: "label",
          stroke: blueDark,
          tick: function CustomizedYAxisTick(_ref2) {
            var payload = _ref2.payload,
                x = _ref2.x,
                y = _ref2.y;

            var SPACES_REGEX = /\s/g;
            var maxTextSize = 24;
            return (/*#__PURE__*/_react.default.createElement("g", {
                transform: "translate(".concat(x, ",").concat(y, ")")
              }, /*#__PURE__*/_react.default.createElement("text", {
                className: "".concat(activeIndex !== null && activeIndex !== payload.index ? 'dim' : ''),
                x: -162
              }, "".concat(payload.value.replace(SPACES_REGEX, '').length > maxTextSize ? (0, _ellipsize.default)(payload.value, maxTextSize) : payload.value)))
            );
          },
          tickLine: false,
          tickMargin: 16,
          type: "category",
          width: 214
        }), /*#__PURE__*/_react.default.createElement(_recharts.Tooltip, {
          content: /*#__PURE__*/_react.default.createElement(_TooltipContent.default, {
            showBullet: false,
            showHeader: false,
            totalEntries: totalEntries
          }),
          cursor: {
            fill: 'transparent'
          }
        }), /*#__PURE__*/_react.default.createElement(_recharts.Bar, {
          barCategoryGap: 30,
          barGap: 5,
          dataKey: "count",
          fill: lightBlue,
          onMouseOut: function handleOnMouseOut() {
            setActiveIndex(null);
          },
          onMouseOver: function onMouseOver(_, index) {
            return handleOnMouseOver(index);
          }
        }, data.map(function (_, index) {
          return (/*#__PURE__*/_react.default.createElement(_recharts.Cell, {
              fillOpacity: activeIndex != null && activeIndex != index ? '.5' : 1,
              key: "cell-".concat(index)
            })
          );
        }), /*#__PURE__*/_react.default.createElement(_recharts.LabelList, {
          dataKey: "count",
          fill: white,
          fontSize: 14,
          offset: 16,
          position: "insideRight"
        })))))
      );
    };

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