var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
import React, { useContext, useRef } from "react";
import classnames from "classnames";
import { getZIndexStyle } from "../utils";
import { BORDER_TOP_BOTTOM } from "../utils/constant";
import useHeight from "../hooks/use-height";
import TabbarContext from "./TabbarContext";
import useMergedState from "../hooks/use-merged-state";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const Tabbar = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("tabbar", prefixCls);
  const [current, setCurrent] = useMergedState({
    value: props.value,
    defaultValue: props.defaultValue
  });
  const root = useRef();
  const height = useHeight(root);
  const renderPlaceholder = (renderContent) => {
    return /* @__PURE__ */ React.createElement("div", {
      className: classnames(bem("placeholder")),
      style: {
        height
      }
    }, renderContent());
  };
  const enableSafeArea = () => {
    var _a;
    return (_a = props.safeAreaInsetBottom) != null ? _a : props.fixed;
  };
  const setActive = (active) => {
    var _a;
    if (active !== props.value) {
      (_a = props.onChange) == null ? void 0 : _a.call(props, active);
      setCurrent(active);
    }
  };
  const renderTabbar = () => {
    const {
      fixed,
      zIndex,
      border
    } = props;
    return /* @__PURE__ */ React.createElement(TabbarContext.Provider, {
      value: {
        parent: __spreadProps(__spreadValues({}, props), {
          value: current
        })
      }
    }, /* @__PURE__ */ React.createElement("div", {
      ref: root,
      style: __spreadValues(__spreadValues({}, props.style), getZIndexStyle(zIndex)),
      className: classnames(props.className, bem({
        fixed
      }), {
        [BORDER_TOP_BOTTOM]: border,
        "rc-safe-area-bottom": enableSafeArea()
      })
    }, React.Children.toArray(props.children).filter(Boolean).map((child, index) => /* @__PURE__ */ React.cloneElement(child, {
      setActive,
      index
    }))));
  };
  if (props.fixed && props.placeholder) {
    return renderPlaceholder(renderTabbar);
  }
  return renderTabbar();
};
Tabbar.defaultProps = {
  fixed: true,
  border: true,
  defaultValue: 0
};
var stdin_default = Tabbar;
export {
  stdin_default as default
};
