"use strict";

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireWildcard(require("react"));

var _clsx = _interopRequireDefault(require("clsx"));

var _TabsContext = _interopRequireDefault(require("./TabsContext"));

var _hooks = require("../hooks");

var _ConfigProviderContext = _interopRequireDefault(require("../config-provider/ConfigProviderContext"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var TabPane = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var _useContext = (0, _react.useContext)(_ConfigProviderContext.default),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('tab', prefixCls),
      bem = _createNamespace[0];

  var parent = (0, _react.useContext)(_TabsContext.default);
  var _parent$props = parent.props,
      animated = _parent$props.animated,
      swipeable = _parent$props.swipeable,
      scrollspy = _parent$props.scrollspy,
      lazyRender = _parent$props.lazyRender,
      lazyRenderPlaceholder = _parent$props.lazyRenderPlaceholder;
  var index = props.index;
  var name = (0, _react.useMemo)(function () {
    var _props$name;

    return (_props$name = props.name) != null ? _props$name : index;
  }, [index, props.name]);
  var active = (0, _react.useMemo)(function () {
    return name === parent.currentName;
  }, [name, parent.currentName]);

  var _useState = (0, _react.useState)(function () {
    return active;
  }),
      inited = _useState[0],
      setInited = _useState[1];

  var init = function init() {
    setInited(true);
  };

  var isActive = (0, _react.useMemo)(function () {
    if (active && !inited) {
      init();
    }

    return active;
  }, [active, inited]);
  (0, _hooks.useUpdateEffect)(function () {
    parent.setLine();
    parent.scrollIntoView();
  }, [props.title]);
  var show = scrollspy || isActive;
  var shouldRender = inited || scrollspy || !lazyRender;
  var Content = shouldRender ? props.children : lazyRenderPlaceholder;

  if (animated || swipeable) {
    return /*#__PURE__*/_react.default.createElement("div", {
      ref: ref,
      role: "tabpanel",
      className: (0, _clsx.default)(bem('pane'))
    }, Content);
  }

  return /*#__PURE__*/_react.default.createElement("div", {
    ref: ref,
    style: {
      display: show ? 'block' : 'none'
    },
    role: "tabpanel",
    className: (0, _clsx.default)(bem('pane'))
  }, Content);
});
TabPane.defaultProps = {
  showZeroBadge: true
};
var _default = TabPane;
exports.default = _default;