import React, { useRef, useEffect, useContext } from "react";
import classnames from "classnames";
import Swiper from "../swiper";
import ConfigProviderContext from "../config-provider/ConfigProviderContext";
const TabsContent = (props) => {
  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace("tabs", prefixCls);
  const swipeRef = useRef();
  const innerEffect = useRef(false);
  const {
    animated,
    swipeable,
    duration
  } = props;
  const renderChildren = () => {
    if (animated || swipeable) {
      return /* @__PURE__ */ React.createElement(Swiper, {
        ref: swipeRef,
        loop: false,
        autoplay: false,
        allowTouchMove: swipeable,
        className: classnames(bem("track")),
        autoplayInterval: +duration,
        indicator: false,
        onIndexChange: (idx) => {
          var _a;
          if (innerEffect.current) {
            innerEffect.current = false;
            return;
          }
          (_a = props.onChange) == null ? void 0 : _a.call(props, idx);
        }
      }, React.Children.map(props.children, (child) => /* @__PURE__ */ React.createElement(Swiper.Item, {
        style: {
          cursor: !swipeable ? "auto" : void 0
        },
        className: classnames(bem("pane-wrapper"))
      }, child)));
    }
    return props.children;
  };
  const swipeToCurrentTab = (index) => {
    const swipe = swipeRef.current;
    if (!swipe)
      return;
    if (swipe.activeIndex !== index) {
      innerEffect.current = true;
      swipe.swipeTo(index);
    }
  };
  useEffect(() => {
    swipeToCurrentTab(props.currentIndex);
  }, [props.currentIndex]);
  return /* @__PURE__ */ React.createElement("div", {
    className: classnames(bem("content", {
      animated: animated || swipeable
    }))
  }, renderChildren());
};
var stdin_default = TabsContent;
export {
  stdin_default as default
};
