"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TabbarItem", {
    enumerable: true,
    get: function() {
        return TabbarItem;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
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 _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
var _classnames = /*#__PURE__*/ _interop_require_default._(require("classnames"));
var _typings = require("../../utils/typings");
var _index = /*#__PURE__*/ _interop_require_default._(require("../badge/index"));
var _context = /*#__PURE__*/ _interop_require_default._(require("../tabbar/context"));
var defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    title: '',
    icon: null,
    value: '',
    dot: false,
    max: 99,
    top: '0',
    right: '0'
});
var TabbarItem = function TabbarItem(props) {
    var ctx = (0, _react.useContext)(_context.default);
    var _ref = (0, _object_spread._)({}, defaultProps, props), className = _ref.className, style = _ref.style, title = _ref.title, icon = _ref.icon, value = _ref.value, dot = _ref.dot, max = _ref.max, top = _ref.top, right = _ref.right, index = _ref.index, rest = (0, _object_without_properties._)(_ref, [
        "className",
        "style",
        "title",
        "icon",
        "value",
        "dot",
        "max",
        "top",
        "right",
        "index"
    ]);
    var active = index === (ctx === null || ctx === void 0 ? void 0 : ctx.selectIndex);
    var classPrefix = 'nut-tabbar-item';
    var tabbarItemClass = (0, _classnames.default)(classPrefix, (0, _define_property._)({}, "".concat(classPrefix, "-active"), active), className);
    var boxPrefix = "".concat(classPrefix, "-icon-box");
    var titleClass = (0, _classnames.default)(boxPrefix, "".concat(boxPrefix, "-nav"), (0, _define_property._)({}, "".concat(boxPrefix, "-large"), !icon));
    var badgeProps = {
        value: value,
        dot: dot,
        max: max,
        top: top,
        right: right,
        color: ctx === null || ctx === void 0 ? void 0 : ctx.activeColor
    };
    var renderTitleText = function renderTitleText() {
        return title && /*#__PURE__*/ _react.default.createElement("div", {
            className: titleClass
        }, title);
    };
    return /*#__PURE__*/ _react.default.createElement("div", (0, _object_spread._)({
        className: tabbarItemClass,
        style: (0, _object_spread._)({
            color: active ? ctx === null || ctx === void 0 ? void 0 : ctx.activeColor : ctx === null || ctx === void 0 ? void 0 : ctx.inactiveColor
        }, style),
        onClick: function onClick() {
            return ctx === null || ctx === void 0 ? void 0 : ctx.handleClick(index);
        }
    }, rest), icon ? /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_index.default, badgeProps, /*#__PURE__*/ _react.default.createElement("div", {
        className: boxPrefix
    }, icon)), renderTitleText()) : /*#__PURE__*/ _react.default.createElement(_index.default, badgeProps, renderTitleText()));
};
