import { _ as _define_property } from "@swc/helpers/_/_define_property";
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, { useContext } from "react";
import classNames from "classnames";
import { ComponentDefaults } from "../../utils/typings";
import Badge from "../badge/index";
import TabbarContext from "../tabbar/context";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    title: '',
    icon: null,
    value: '',
    dot: false,
    max: 99,
    top: '0',
    right: '0'
});
export var TabbarItem = function(props) {
    var ctx = useContext(TabbarContext);
    var _ref = _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, // @ts-ignore
    index = _ref.index, rest = _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 = classNames(classPrefix, _define_property({}, "".concat(classPrefix, "-active"), active), className);
    var boxPrefix = "".concat(classPrefix, "-icon-box");
    var titleClass = classNames(boxPrefix, "".concat(boxPrefix, "-nav"), _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() {
        return title && /*#__PURE__*/ React.createElement("div", {
            className: titleClass
        }, title);
    };
    return /*#__PURE__*/ React.createElement("div", _object_spread({
        className: tabbarItemClass,
        style: _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() {
            return ctx === null || ctx === void 0 ? void 0 : ctx.handleClick(index);
        }
    }, rest), icon ? /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(Badge, badgeProps, /*#__PURE__*/ React.createElement("div", {
        className: boxPrefix
    }, icon)), renderTitleText()) : /*#__PURE__*/ React.createElement(Badge, badgeProps, renderTitleText()));
};
