"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TrendArrow", {
    enumerable: true,
    get: function() {
        return TrendArrow;
    }
});
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _object_spread = require("@swc/helpers/_/_object_spread");
var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _iconsreacttaro = require("@nutui/icons-react-taro");
var _components = require("@tarojs/components");
var _typings = require("../../utils/typings");
var _platform = require("../../utils/taro/platform");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    value: 0,
    digits: 2,
    symbol: false,
    zero: false,
    left: false,
    sync: true,
    color: '#333',
    riseColor: (0, _platform.harmony)() ? '#ff0f23' : 'var(--nutui-brand-6)',
    dropColor: (0, _platform.harmony)() ? '#14cc33' : 'var(--nutui-secondary-1)',
    riseIcon: null,
    dropIcon: null
});
var TrendArrow = function TrendArrow(props) {
    var _ref = (0, _object_spread._)({}, defaultProps, props), value = _ref.value, digits = _ref.digits, symbol = _ref.symbol, zero = _ref.zero, left = _ref.left, sync = _ref.sync, color = _ref.color, riseColor = _ref.riseColor, dropColor = _ref.dropColor, riseIcon = _ref.riseIcon, dropIcon = _ref.dropIcon, className = _ref.className, style = _ref.style, children = _ref.children, rest = (0, _object_without_properties._)(_ref, [
        "value",
        "digits",
        "symbol",
        "zero",
        "left",
        "sync",
        "color",
        "riseColor",
        "dropColor",
        "riseIcon",
        "dropIcon",
        "className",
        "style",
        "children"
    ]);
    var classPrefix = 'nut-trendarrow';
    var rateTrend = (0, _react.useRef)(value > 0);
    var myFixed = function myFixed(num) {
        var digit = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2;
        if (Object.is(parseFloat(num), NaN)) {
            return console.warn("传入的值：".concat(num, "不是一个数字"));
        }
        num = parseFloat(num);
        // eslint-disable-next-line no-restricted-properties
        var numPow = Math.pow(10, digit);
        return (Math.round((num + Number.EPSILON) * numPow) / numPow).toFixed(digit);
    };
    var calcStyle = function() {
        var arrowColor = rateTrend.current ? riseColor : dropColor;
        var textEquArrowColor = sync ? arrowColor : color;
        var style = {
            color: value === 0 ? color : textEquArrowColor
        };
        return style;
    }();
    var calcRate = function() {
        rateTrend.current = value > 0;
        var absRate = Math.abs(value);
        if (!zero && value === 0) {
            return '--';
        }
        var resultRate = "".concat(symbol && value !== 0 ? rateTrend.current ? '+' : '-' : '').concat(myFixed(Number(absRate), digits), "%");
        return resultRate;
    }();
    var calcIconProps = function() {
        var iconProps = {
            color: rateTrend.current ? riseColor : dropColor
        };
        return iconProps;
    }();
    var renderContent = function renderContent(left) {
        var classNameSuffix = !left ? 'icon-after' : 'icon-before';
        return /*#__PURE__*/ _react.default.createElement(_components.Text, {
            className: "".concat(classPrefix, "-").concat(classNameSuffix, " ").concat(classPrefix, "-value"),
            style: calcStyle
        }, calcRate);
    };
    return /*#__PURE__*/ _react.default.createElement(_components.View, (0, _object_spread._)({
        className: "".concat(classPrefix, " ").concat(className),
        style: style
    }, rest), !left && renderContent(!left), Number(value) !== 0 && /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, rateTrend.current ? /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, riseIcon || /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.TriangleUp, {
        color: calcIconProps.color
    })) : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, dropIcon || /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.TriangleDown, {
        color: calcIconProps.color
    }))), left && renderContent(!left));
};
TrendArrow.displayName = 'NutTrendArrow';
