"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _FunnelChartSt = require("./FunnelChart.st.css.js");
var _FunnelLabel = require("./FunnelLabel");
var _FunnelBar = require("./FunnelBar");
var _FunnelStep = require("./FunnelStep");
var _numberFormatters = require("../utils/numberFormatters");
var _constants = require("./constants");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/FunnelChart/FunnelChart.jsx",
  _this = void 0;
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
// TODO - this can be memoized
var calculateBarsHeights = function calculateBarsHeights(_ref) {
  var funnelChartData = _ref.funnelChartData,
    startValue = _ref.startValue;
  return funnelChartData.map(function (i) {
    var percentage = (0, _numberFormatters.countPercentageFromBase)(startValue, i.value, 0);
    return percentage > 100 ? 100 : percentage;
  });
};

/** FunnelChart */
var FunnelChart = function FunnelChart(_ref2) {
  var dataHook = _ref2.dataHook,
    className = _ref2.className,
    data = _ref2.data,
    hideDifferenceBadge = _ref2.hideDifferenceBadge,
    fullHeight = _ref2.fullHeight,
    _ref2$differenceBadge = _ref2.differenceBadgeSkin,
    differenceBadgeSkin = _ref2$differenceBadge === void 0 ? 'standard' : _ref2$differenceBadge,
    _ref2$differenceBadge2 = _ref2.differenceBadgeProps,
    differenceBadgeProps = _ref2$differenceBadge2 === void 0 ? function () {
      return {};
    } : _ref2$differenceBadge2,
    _ref2$differenceBadge3 = _ref2.differenceBadgeTooltipContent,
    differenceBadgeTooltipContent = _ref2$differenceBadge3 === void 0 ? function () {
      return '';
    } : _ref2$differenceBadge3,
    _ref2$differenceBadge4 = _ref2.differenceBadgeTooltipProps,
    differenceBadgeTooltipProps = _ref2$differenceBadge4 === void 0 ? function () {
      return {};
    } : _ref2$differenceBadge4,
    _ref2$onDifferenceBad = _ref2.onDifferenceBadgeTooltipShow,
    onDifferenceBadgeTooltipShow = _ref2$onDifferenceBad === void 0 ? function () {} : _ref2$onDifferenceBad,
    _ref2$differenceStepS = _ref2.differenceStepSkin,
    differenceStepSkin = _ref2$differenceStepS === void 0 ? function () {
      return 'standard';
    } : _ref2$differenceStepS;
  if (data.length < 2) {
    return null;
  }
  var barsHeights = calculateBarsHeights({
    funnelChartData: data,
    startValue: data[0].value
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    "data-hook": dataHook,
    className: (0, _FunnelChartSt.st)(_FunnelChartSt.classes.root, className),
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 41,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react["default"].createElement("section", {
    className: (0, _FunnelChartSt.st)(_FunnelChartSt.classes.funnel, {
      fullHeight: fullHeight
    }),
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 42,
      columnNumber: 7
    }
  }, data.map(function (item, index) {
    var currentBarHeight = barsHeights[index];
    var nextBarHeight = barsHeights[index + 1];
    var isLastItem = index === data.length - 1;
    return /*#__PURE__*/_react["default"].createElement(_react.Fragment, {
      key: item.label,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 50,
        columnNumber: 13
      }
    }, /*#__PURE__*/_react["default"].createElement(_FunnelBar.FunnelBar, {
      height: currentBarHeight,
      dataHook: _constants.dataHooks.funnelChartItem,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 51,
        columnNumber: 15
      }
    }), isLastItem || data[index + 1].value === 0 ? /*#__PURE__*/_react["default"].createElement(_FunnelStep.EmptyFunnelStep, {
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 56,
        columnNumber: 17
      }
    }) : /*#__PURE__*/_react["default"].createElement(_FunnelStep.FunnelStep, {
      currentBarIndex: index,
      currentBarData: data[index],
      nextBarData: data[index + 1],
      currentBarHeight: currentBarHeight,
      nextBarHeight: nextBarHeight,
      hideDifferenceBadge: hideDifferenceBadge,
      differenceBadgeSkin: differenceBadgeSkin // mark as deprecated
      ,
      getDifferenceBadgeProps: differenceBadgeProps,
      getDifferenceStepSkin: differenceStepSkin,
      getTooltipContent: differenceBadgeTooltipContent,
      getTooltipProps: differenceBadgeTooltipProps,
      onTooltipShow: onDifferenceBadgeTooltipShow,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 58,
        columnNumber: 17
      }
    }));
  })), /*#__PURE__*/_react["default"].createElement("section", {
    className: _FunnelChartSt.classes.labels,
    __self: _this,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 77,
      columnNumber: 7
    }
  }, data.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: item.label,
      className: _FunnelChartSt.classes.labelWrapper,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 80,
        columnNumber: 13
      }
    }, /*#__PURE__*/_react["default"].createElement(_FunnelLabel.FunnelLabel, {
      value: item.value,
      label: item.label,
      displayValue: item.displayValue,
      __self: _this,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 81,
        columnNumber: 15
      }
    }));
  })));
};
FunnelChart.displayName = 'FunnelChart';
var _default = exports["default"] = FunnelChart;