"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Badge", {
    enumerable: true,
    get: function() {
        return Badge;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
var _async_to_generator = require("@swc/helpers/_/_async_to_generator");
var _define_property = require("@swc/helpers/_/_define_property");
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 _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
var _type_of = require("@swc/helpers/_/_type_of");
var _ts_generator = require("@swc/helpers/_/_ts_generator");
var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _components = require("@tarojs/components");
var _typings = require("../../utils/typings");
var _index = require("../configprovider/index");
var _pxtransform = require("../../utils/taro/px-transform");
var _platform = require("../../utils/taro/platform");
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    value: '',
    dot: false,
    max: 99,
    top: 0,
    right: 0,
    fill: 'solid',
    size: 'large',
    disabled: false
});
var Badge = function Badge(props) {
    var getContent = function getContent() {
        if (dot || value === 0) return null;
        if (typeof value === 'number') {
            return max < value ? "".concat(max, "+") : "".concat(value);
        }
        return value;
    };
    var isIcon = function isIcon() {
        if ((typeof value === "undefined" ? "undefined" : (0, _type_of._)(value)) === 'object' && value) return value;
    };
    var isNumber = function isNumber() {
        if (typeof value === 'number' && value) return value;
    };
    var isString = function isString() {
        if (typeof value === 'string' && value) return value;
    };
    var _this;
    var rtl = (0, _index.useRtl)();
    var _ref = (0, _object_spread._)({}, defaultProps, props), className = _ref.className, style = _ref.style, value = _ref.value, max = _ref.max, children = _ref.children, dot = _ref.dot, top = _ref.top, right = _ref.right, fill = _ref.fill, size = _ref.size, disabled = _ref.disabled, rest = (0, _object_without_properties._)(_ref, [
        "className",
        "style",
        "value",
        "max",
        "children",
        "dot",
        "top",
        "right",
        "fill",
        "size",
        "disabled"
    ]);
    var classPrefix = 'nut-badge';
    var isHarmony = (0, _platform.harmony)();
    var classes = (0, _classnames.default)(classPrefix, className);
    var badgeRef = (0, _react.useRef)(null);
    var _useState = (0, _sliced_to_array._)((0, _react.useState)({}), 2), contentStyle = _useState[0], setContentStyle = _useState[1];
    var _obj;
    var contentClasses = (0, _classnames.default)((_obj = {}, (0, _define_property._)(_obj, "".concat(classPrefix, "-sup"), isNumber() || isString() || dot), (0, _define_property._)(_obj, "".concat(classPrefix, "-number"), isNumber()), (0, _define_property._)(_obj, "".concat(classPrefix, "-one"), typeof getContent() === 'string' && ((_this = "".concat(getContent())) === null || _this === void 0 ? void 0 : _this.length) === 1), (0, _define_property._)(_obj, "".concat(classPrefix, "-dot"), dot), (0, _define_property._)(_obj, "".concat(classPrefix, "-dot-").concat(size), dot), (0, _define_property._)(_obj, "".concat(classPrefix, "-").concat(fill), fill === 'outline'), (0, _define_property._)(_obj, "".concat(classPrefix, "-content"), children), (0, _define_property._)(_obj, "".concat(classPrefix, "-disabled"), disabled), _obj));
    (0, _react.useEffect)(function() {
        if (badgeRef.current) {
            getPositionStyle();
        }
    }, []);
    var getPositionStyle = function getPositionStyle() {
        return (0, _async_to_generator._)(function() {
            var style;
            return (0, _ts_generator._)(this, function(_state) {
                style = (0, _define_property._)({
                    top: (0, _pxtransform.pxTransform)(Number(top) || 0)
                }, rtl ? 'left' : 'right', isHarmony ? (0, _pxtransform.pxTransform)(Number(right)) : "".concat(Number(right) || 0, "px"));
                setContentStyle(style);
                return [
                    2
                ];
            });
        })();
    };
    var _obj1;
    return /*#__PURE__*/ _react.default.createElement(_components.View, (0, _object_spread._)({
        className: classes,
        style: style,
        ref: badgeRef
    }, rest), isIcon() && /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: (0, _classnames.default)("".concat(classPrefix, "-content"), (_obj1 = {}, (0, _define_property._)(_obj1, "".concat(classPrefix, "-icon"), true), (0, _define_property._)(_obj1, "".concat(classPrefix, "-icon-rtl"), rtl), _obj1)),
        style: contentStyle
    }, value), children, !isIcon() && (getContent() || dot) && /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: contentClasses,
        style: contentStyle
    }, getContent()));
};
Badge.displayName = 'NutBadge';
