"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _system = require("@wix/wix-ui-icons-common/system");
var _TrendIndicatorSt = require("./TrendIndicator.st.css.js");
var _TrendIndicator = require("./TrendIndicator.constants");
var _context = require("../WixStyleReactEnvironmentProvider/context");
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/TrendIndicator/TrendIndicator.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 TrendIndicatorInner = _ref => {
  var {
    value,
    inverted = false,
    className,
    dataHook,
    locale,
    format = 'percent'
  } = _ref;
  var context = (0, _react.useContext)(_context.WixStyleReactEnvironmentContext);
  var effectiveLocale = locale || context.locale;
  if (isNaN(Number(value))) {
    return null;
  }
  var skin = 'neutral';
  var trendIcon = null;
  if (value > 0) {
    trendIcon = /*#__PURE__*/_react.default.createElement(_system.SortByArrowUp, {
      "data-hook": _TrendIndicator.dataHooks.trendIndicatorUp,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 30,
        columnNumber: 17
      }
    });
    skin = !inverted ? 'positive' : 'negative';
  } else if (value < 0) {
    trendIcon = /*#__PURE__*/_react.default.createElement(_system.SortByArrowDown, {
      "data-hook": _TrendIndicator.dataHooks.trendIndicatorDown,
      __self: void 0,
      __source: {
        fileName: _jsxFileName,
        lineNumber: 33,
        columnNumber: 17
      }
    });
    skin = !inverted ? 'negative' : 'positive';
  }
  return /*#__PURE__*/_react.default.createElement("div", {
    className: (0, _TrendIndicatorSt.st)(_TrendIndicatorSt.classes.root, {
      skin
    }, className),
    "data-hook": dataHook,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 38,
      columnNumber: 5
    }
  }, /*#__PURE__*/_react.default.createElement("div", {
    className: _TrendIndicatorSt.classes.caption,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 39,
      columnNumber: 7
    }
  }, !!value && /*#__PURE__*/_react.default.createElement("span", {
    className: _TrendIndicatorSt.classes.icon,
    "data-hook": _TrendIndicator.dataHooks.trendIndicatorIcon,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 41,
      columnNumber: 11
    }
  }, trendIcon), /*#__PURE__*/_react.default.createElement("span", {
    "data-hook": _TrendIndicator.dataHooks.trendIndicatorValue,
    __self: void 0,
    __source: {
      fileName: _jsxFileName,
      lineNumber: 48,
      columnNumber: 9
    }
  }, new Intl.NumberFormat(effectiveLocale, {
    style: format
  }).format(Math.abs(value) / (format === 'percent' ? 100 : 1)))));
};
var TrendIndicator = props => /*#__PURE__*/_react.default.createElement(_context.WixStyleReactEnvironmentContext.Provider, {
  value: {
    locale: 'en'
  },
  __self: void 0,
  __source: {
    fileName: _jsxFileName,
    lineNumber: 59,
    columnNumber: 3
  }
}, /*#__PURE__*/_react.default.createElement(TrendIndicatorInner, (0, _extends2.default)({}, props, {
  __self: void 0,
  __source: {
    fileName: _jsxFileName,
    lineNumber: 60,
    columnNumber: 5
  }
})));
TrendIndicator.displayName = 'TrendIndicator';
var _default = exports.default = TrendIndicator;
//# sourceMappingURL=TrendIndicator.js.map