"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = exports.AnalyticsSummaryCard = void 0;
var _react = _interopRequireWildcard(require("react"));
var _noop = _interopRequireDefault(require("lodash/noop"));
var _Heading = _interopRequireDefault(require("../Heading"));
var _Tooltip = _interopRequireDefault(require("../Tooltip"));
var _SparklineChart = _interopRequireDefault(require("../SparklineChart"));
var _TrendIndicator = _interopRequireDefault(require("../TrendIndicator"));
var _Text = _interopRequireDefault(require("../Text"));
var _Loader = _interopRequireDefault(require("../Loader"));
var _AnalyticsSummaryCardSt = require("./AnalyticsSummaryCard.st.css.js");
var _AnalyticsSummaryCard = require("./AnalyticsSummaryCard.constants");
var _Focusable = require("../common/Focusable");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/AnalyticsSummaryCard/AnalyticsSummaryCard.tsx";
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); }
var SPARKLINE_HEIGHT = 22;

// storybook utils can't unwrap HOC, hence the export
var AnalyticsSummaryCard = _ref => {
  var {
    isLoading = false,
    ctaButton = null,
    footer = null,
    onChartHover = _noop.default,
    isTrendVisible = false,
    alwaysShowCTA = false,
    chartWidth = 69,
    chartAnimationDuration = 300,
    onClick,
    onCTAClick,
    title,
    titleTooltip,
    value,
    valueTooltip,
    dataHook,
    className,
    trend,
    invertedTrend,
    chartData,
    chartColorHex,
    chartHighlightedStartingIndex,
    getChartTooltipContent,
    focusableOnFocus,
    focusableOnBlur,
    border = false,
    horizontalPadding = _AnalyticsSummaryCard.HORIZONTAL_PADDING.large
  } = _ref;
  var [isHovered, setIsHovered] = (0, _react.useState)(false);
  var handleMouseEnter = (0, _react.useCallback)(() => setIsHovered(true), []);
  var handleMouseLeave = (0, _react.useCallback)(() => setIsHovered(false), []);
  var handleClick = (0, _react.useCallback)(event => onClick == null ? void 0 : onClick(event), [onClick]);
  var handleCTAClick = (0, _react.useCallback)(event => {
    event.stopPropagation();
    onCTAClick == null || onCTAClick(event);
  }, [onCTAClick]);
  var shouldShowCTA = (0, _react.useMemo)(() => !isLoading && ctaButton && (isHovered || alwaysShowCTA), [alwaysShowCTA, ctaButton, isHovered, isLoading]);
  var renderTitle = (0, _react.useCallback)(() => /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
    placement: "top",
    content: titleTooltip,
    disabled: !titleTooltip,
    dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardTitleTooltip,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 74,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement("span", {
    "data-hook": _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardTitle,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 80,
      columnNumber: 9
    }
  }, title)), [title, titleTooltip]);
  var renderValue = (0, _react.useCallback)(() => {
    if (valueTooltip) {
      return /*#__PURE__*/_react.default.createElement(_Tooltip.default, {
        placement: "top",
        content: valueTooltip,
        dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardValueTooltip,
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 89,
          columnNumber: 9
        }
      }, /*#__PURE__*/_react.default.createElement(_Text.default, {
        tagName: "span",
        weight: "bold",
        dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardValue,
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 94,
          columnNumber: 11
        }
      }, value));
    } else {
      return /*#__PURE__*/_react.default.createElement(_Text.default, {
        tagName: "span",
        weight: "bold",
        dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardValue,
        __self: void 0,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 105,
          columnNumber: 9
        }
      }, value);
    }
  }, [value, valueTooltip]);
  var isClickable = (0, _react.useMemo)(() => onClick !== undefined, [onClick]);
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _AnalyticsSummaryCardSt.st)(_AnalyticsSummaryCardSt.classes.root, {
      hovered: isHovered,
      clickable: isClickable,
      border,
      horizontalPadding
    }, className),
    "data-hook": dataHook,
    onClick: handleClick,
    onMouseEnter: handleMouseEnter,
    onMouseLeave: handleMouseLeave,
    onFocus: focusableOnFocus,
    onBlur: focusableOnBlur,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 119,
      columnNumber: 5
    }
  }, isLoading && /*#__PURE__*/_react.default.createElement("div", {
    className: _AnalyticsSummaryCardSt.classes.loader,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 139,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(_Loader.default, {
    dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardLoader,
    size: "tiny",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 140,
      columnNumber: 11
    }
  })), shouldShowCTA && /*#__PURE__*/_react.default.createElement("div", {
    "data-hook": _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardCTA,
    className: (0, _AnalyticsSummaryCardSt.st)(_AnalyticsSummaryCardSt.classes.ctaButton),
    onClick: handleCTAClick,
    onFocus: focusableOnFocus,
    onBlur: focusableOnBlur,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 146,
      columnNumber: 9
    }
  }, ctaButton), /*#__PURE__*/_react.default.createElement("div", {
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 157,
      columnNumber: 7
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _AnalyticsSummaryCardSt.st)(_AnalyticsSummaryCardSt.classes.title),
    onFocus: focusableOnFocus,
    onBlur: focusableOnBlur,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 159,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement(_Heading.default, {
    size: "extraTiny",
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 164,
      columnNumber: 11
    }
  }, renderTitle())), /*#__PURE__*/_react.default.createElement("div", {
    className: _AnalyticsSummaryCardSt.classes.valueLineContainer,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 168,
      columnNumber: 9
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _AnalyticsSummaryCardSt.classes.valueAndTrend,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 169,
      columnNumber: 11
    }
  }, renderValue(), isTrendVisible && trend !== undefined && /*#__PURE__*/_react.default.createElement(_TrendIndicator.default, {
    dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardTrend,
    className: _AnalyticsSummaryCardSt.classes.trend,
    value: trend,
    inverted: invertedTrend,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 172,
      columnNumber: 15
    }
  })), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _AnalyticsSummaryCardSt.st)(_AnalyticsSummaryCardSt.classes.sparkline),
    onFocus: focusableOnFocus,
    onBlur: focusableOnBlur,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 182,
      columnNumber: 11
    }
  }, /*#__PURE__*/_react.default.createElement(_SparklineChart.default, {
    dataHook: _AnalyticsSummaryCard.dataHooks.analyticsSummaryCardChart,
    onHover: onChartHover,
    data: chartData,
    color: chartColorHex,
    width: chartWidth,
    height: SPARKLINE_HEIGHT,
    highlightedStartingIndex: chartHighlightedStartingIndex,
    getTooltipContent: getChartTooltipContent,
    animationDuration: chartAnimationDuration,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 187,
      columnNumber: 13
    }
  }))), /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _AnalyticsSummaryCardSt.st)(_AnalyticsSummaryCardSt.classes.footer),
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 200,
      columnNumber: 9
    }
  }, " ", footer)));
};
exports.AnalyticsSummaryCard = AnalyticsSummaryCard;
AnalyticsSummaryCard.displayName = 'AnalyticsSummaryCard';
var _default = exports.default = (0, _Focusable.withFocusable)(AnalyticsSummaryCard);
//# sourceMappingURL=AnalyticsSummaryCard.js.map