import b from "../../@babel/runtime/helpers/esm/extends.mjs";
import f from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import A from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import c from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import me from "../../@babel/runtime/helpers/esm/typeof.mjs";
import se from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import ue from "../../classnames/index.mjs";
import K from "../../rc-util/es/hooks/useMergedState.mjs";
import be from "../../rc-util/es/isMobile.mjs";
import * as i from "react";
import { useState as k, useEffect as v } from "react";
import fe from "./hooks/useAnimateConfig.mjs";
import ve from "./TabContext.mjs";
import Ce from "./TabNavList/Wrapper.mjs";
import Te from "./TabPanelList/index.mjs";
var ye = ["id", "prefixCls", "className", "items", "direction", "activeKey", "defaultActiveKey", "editable", "animated", "tabPosition", "tabBarGutter", "tabBarStyle", "tabBarExtraContent", "locale", "moreIcon", "moreTransitionName", "destroyInactiveTabPane", "renderTabBar", "onChange", "onTabClick", "onTabScroll", "getPopupContainer", "popupClassName", "indicatorSize"], j = 0, Se = /* @__PURE__ */ i.forwardRef(function(e, z) {
  var n, d = e.id, C = e.prefixCls, r = C === void 0 ? "rc-tabs" : C, G = e.className, T = e.items, V = e.direction, D = e.activeKey, L = e.defaultActiveKey, y = e.editable, O = e.animated, S = e.tabPosition, N = S === void 0 ? "top" : S, R = e.tabBarGutter, W = e.tabBarStyle, $ = e.tabBarExtraContent, q = e.locale, w = e.moreIcon, F = e.moreTransitionName, H = e.destroyInactiveTabPane, J = e.renderTabBar, m = e.onChange, s = e.onTabClick, Q = e.onTabScroll, U = e.getPopupContainer, X = e.popupClassName, Y = e.indicatorSize, Z = se(e, ye), a = i.useMemo(function() {
    return (T || []).filter(function(t) {
      return t && me(t) === "object" && "key" in t;
    });
  }, [T]), g = V === "rtl", P = fe(O), ee = k(!1), _ = c(ee, 2), x = _[0], te = _[1];
  v(function() {
    te(be());
  }, []);
  var ae = K(function() {
    var t;
    return (t = a[0]) === null || t === void 0 ? void 0 : t.key;
  }, {
    value: D,
    defaultValue: L
  }), B = c(ae, 2), o = B[0], I = B[1], re = k(function() {
    return a.findIndex(function(t) {
      return t.key === o;
    });
  }), p = c(re, 2), E = p[0], ie = p[1];
  v(function() {
    var t = a.findIndex(function(u) {
      return u.key === o;
    });
    if (t === -1) {
      var l;
      t = Math.max(0, Math.min(E, a.length - 1)), I((l = a[t]) === null || l === void 0 ? void 0 : l.key);
    }
    ie(t);
  }, [a.map(function(t) {
    return t.key;
  }).join("_"), o, E]);
  var ne = K(null, {
    value: d
  }), M = c(ne, 2), oe = M[0], le = M[1];
  v(function() {
    d || (le("rc-tabs-".concat(process.env.NODE_ENV === "test" ? "test" : j)), j += 1);
  }, []);
  function ce(t, l) {
    s == null || s(t, l);
    var u = t !== o;
    I(t), u && (m == null || m(t));
  }
  var h = {
    id: oe,
    activeKey: o,
    animated: P,
    tabPosition: N,
    rtl: g,
    mobile: x
  }, de = A(A({}, h), {}, {
    editable: y,
    locale: q,
    moreIcon: w,
    moreTransitionName: F,
    tabBarGutter: R,
    onTabClick: ce,
    onTabScroll: Q,
    extra: $,
    style: W,
    panes: null,
    getPopupContainer: U,
    popupClassName: X,
    indicatorSize: Y
  });
  return /* @__PURE__ */ i.createElement(ve.Provider, {
    value: {
      tabs: a,
      prefixCls: r
    }
  }, /* @__PURE__ */ i.createElement("div", b({
    ref: z,
    id: d,
    className: ue(r, "".concat(r, "-").concat(N), (n = {}, f(n, "".concat(r, "-mobile"), x), f(n, "".concat(r, "-editable"), y), f(n, "".concat(r, "-rtl"), g), n), G)
  }, Z), /* @__PURE__ */ i.createElement(Ce, b({}, de, {
    renderTabBar: J
  })), /* @__PURE__ */ i.createElement(Te, b({
    destroyInactiveTabPane: H
  }, h, {
    animated: P
  }))));
});
process.env.NODE_ENV !== "production" && (Se.displayName = "Tabs");
export {
  Se as default
};
