import React, { useState, useContext, useMemo, forwardRef } from "react";
import classnames from "classnames";
import TabsContext from "./TabsContext";
import { useUpdateEffect } from "../hooks";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const TabPane = /* @__PURE__ */ forwardRef((props, ref) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("tab", prefixCls);
  const parent = useContext(TabsContext);
  const [inited, setInited] = useState(false);
  const {
    animated,
    swipeable,
    scrollspy,
    lazyRender
  } = parent.props;
  const {
    index
  } = props;
  const getName = () => {
    var _a;
    return (_a = props.name) != null ? _a : index;
  };
  const init = () => {
    setInited(true);
  };
  const isActive = useMemo(() => {
    const active = getName() === parent.currentName;
    if (active && !inited) {
      init();
    }
    return active;
  }, [inited, parent.currentName]);
  useUpdateEffect(() => {
    parent.setLine();
    parent.scrollIntoView();
  }, [props.title]);
  const show = scrollspy || isActive;
  if (animated || swipeable) {
    return /* @__PURE__ */ React.createElement("div", {
      className: classnames(bem("pane"))
    }, props.children);
  }
  const shouldRender = inited || scrollspy || !lazyRender;
  const Content = shouldRender ? props.children : null;
  return /* @__PURE__ */ React.createElement("div", {
    ref,
    style: {
      display: show ? "block" : "none"
    },
    role: "tabpanel",
    className: classnames(bem("pane"))
  }, Content);
});
TabPane.defaultProps = {
  showZeroBadge: true
};
var stdin_default = TabPane;
export {
  stdin_default as default
};
