import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import React, { useRef } from "react";
import { TriangleDown, TriangleUp } from "@nutui/icons-react-taro";
import { Text, View } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
import { harmony } from "../../utils/taro/platform";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    value: 0,
    digits: 2,
    symbol: false,
    zero: false,
    left: false,
    sync: true,
    color: '#333',
    riseColor: harmony() ? '#ff0f23' : 'var(--nutui-brand-6)',
    dropColor: harmony() ? '#14cc33' : 'var(--nutui-secondary-1)',
    riseIcon: null,
    dropIcon: null
});
export var TrendArrow = function(props) {
    var _ref = _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 = _object_without_properties(_ref, [
        "value",
        "digits",
        "symbol",
        "zero",
        "left",
        "sync",
        "color",
        "riseColor",
        "dropColor",
        "riseIcon",
        "dropIcon",
        "className",
        "style",
        "children"
    ]);
    var classPrefix = 'nut-trendarrow';
    var rateTrend = useRef(value > 0);
    var myFixed = function(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(// eslint-disable-next-line no-nested-ternary
        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(left) {
        var classNameSuffix = !left ? 'icon-after' : 'icon-before';
        return /*#__PURE__*/ React.createElement(Text, {
            className: "".concat(classPrefix, "-").concat(classNameSuffix, " ").concat(classPrefix, "-value"),
            style: calcStyle
        }, calcRate);
    };
    return /*#__PURE__*/ React.createElement(View, _object_spread({
        className: "".concat(classPrefix, " ").concat(className),
        style: style
    }, rest), !left && renderContent(!left), Number(value) !== 0 && /*#__PURE__*/ React.createElement(React.Fragment, null, rateTrend.current ? /*#__PURE__*/ React.createElement(React.Fragment, null, riseIcon || /*#__PURE__*/ React.createElement(TriangleUp, {
        color: calcIconProps.color
    })) : /*#__PURE__*/ React.createElement(React.Fragment, null, dropIcon || /*#__PURE__*/ React.createElement(TriangleDown, {
        color: calcIconProps.color
    }))), left && renderContent(!left));
};
TrendArrow.displayName = 'NutTrendArrow';
