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 _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React from "react";
import classNames from "classnames";
import { ComponentDefaults } from "../../utils/typings";
import { usePropsValue } from "../../hooks/use-props-value";
import TabbarItem from "../tabbaritem";
import TabbarContext from "./context";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    defaultValue: 0,
    fixed: false,
    inactiveColor: '',
    activeColor: '',
    safeArea: false,
    onSwitch: function(value) {}
});
export var Tabbar = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), children = _$_object_spread.children, defaultValue = _$_object_spread.defaultValue, value = _$_object_spread.value, fixed = _$_object_spread.fixed, activeColor = _$_object_spread.activeColor, inactiveColor = _$_object_spread.inactiveColor, safeArea = _$_object_spread.safeArea, className = _$_object_spread.className, style = _$_object_spread.style, onSwitch = _$_object_spread.onSwitch;
    var classPrefix = 'nut-tabbar';
    var _usePropsValue = _sliced_to_array(usePropsValue({
        value: value,
        defaultValue: defaultValue,
        finalValue: 0,
        onChange: onSwitch
    }), 2), selectIndex = _usePropsValue[0], setSelectIndex = _usePropsValue[1];
    return /*#__PURE__*/ React.createElement("div", {
        className: classNames(classPrefix, _define_property({}, "".concat(classPrefix, "-fixed"), fixed), className),
        style: style
    }, /*#__PURE__*/ React.createElement("div", {
        className: "".concat(classPrefix, "-wrap")
    }, /*#__PURE__*/ React.createElement(TabbarContext.Provider, {
        value: {
            selectIndex: selectIndex,
            activeColor: activeColor,
            inactiveColor: inactiveColor,
            handleClick: setSelectIndex
        }
    }, React.Children.map(children, function(child, index) {
        if (!/*#__PURE__*/ React.isValidElement(child)) return null;
        return /*#__PURE__*/ React.cloneElement(child, _object_spread_props(_object_spread({}, child.props), {
            index: index
        }));
    }))), (fixed || safeArea) && /*#__PURE__*/ React.createElement("div", {
        className: "".concat(classPrefix, "-safe-area")
    }));
};
Tabbar.displayName = 'NutTabbar';
Tabbar.Item = TabbarItem;
