"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _tslib = require("tslib");

var _consoleComponents = require("@alicloud/console-components");

var _classnames = _interopRequireDefault(require("classnames"));

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

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

;

var getUuid = function getUuid() {
  function s4() {
    return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
  }

  return s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4();
};

var Container =
/** @class */
function (_super) {
  (0, _tslib.__extends)(Container, _super);

  function Container(props) {
    var _this = _super.call(this, props) || this;

    _this.addPadding = function () {
      var padding = _this.props.type === 'single' ? '20px' : '0px';
      var infoNode = document.getElementById(_this.uuid);

      if (infoNode) {
        infoNode.style.paddingBottom = padding;
      }
    };

    _this.uuid = getUuid();
    return _this;
  }

  Container.prototype.componentDidMount = function () {
    this.addPadding();
  };

  Container.prototype.render = function () {
    var _a = this.props,
        _b = _a.source,
        source = _b === void 0 ? [] : _b,
        children = _a.children,
        isNest = _a.isNest,
        nest = _a.nest,
        _c = _a.tabShap,
        tabShap = _c === void 0 ? 'wrapped' : _c,
        leftTab = _a.leftTab,
        next = _a.next,
        className = _a.className,
        tabsConfig = (0, _tslib.__rest)(_a, ["source", "children", "isNest", "nest", "tabShap", "leftTab", "next", "className"]); // debugger;

    var containerContentType = 'single';
    var tabItems = [],
        needBeLeftTab = false;

    if (source.length > 0) {
      containerContentType = 'tabs';
      tabItems = source.map(function (item, _index) {
        var tabContent;

        if ( /*#__PURE__*/_react["default"].isValidElement(item.content)) {
          var conetentType = item.content.type;

          if (conetentType.displayName === 'LayoutContent' && item.content.props.source.length > 1) {
            needBeLeftTab = true;
          }

          tabContent = /*#__PURE__*/_react["default"].cloneElement(item.content, {
            nest: 1,
            next: 1
          });
        } else {
          tabContent = item.content;
        }

        return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Tab.Item, {
          title: item.title,
          key: item.key
        }, tabContent);
      });
    }

    var leftTabState = leftTab === undefined ? needBeLeftTab : leftTab; // debugger;

    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('lp-container', {
        'lp-nest-container': isNest !== undefined ? isNest : nest
      }, {
        'lp-container-leftTabs': leftTabState
      }, className),
      id: this.uuid
    }, containerContentType === 'single' && /*#__PURE__*/_react["default"].createElement("div", {
      className: "lp-container-content"
    }, _react["default"].Children.map(children, function (child) {
      return /*#__PURE__*/_react["default"].isValidElement(child) ? /*#__PURE__*/_react["default"].cloneElement(child, {
        nest: 1
      }) : child;
    })), containerContentType === 'tabs' && /*#__PURE__*/_react["default"].createElement(_consoleComponents.Tab, (0, _tslib.__assign)({
      shape: leftTabState ? 'wrapped' : tabShap,
      tabPosition: leftTabState ? 'left' : 'top',
      className: next ? "next-tabs-wrapped next-tabs-top" : ""
    }, tabsConfig), tabItems));
  };

  Container.displayName = 'LayoutContent';
  return Container;
}(_react["default"].Component);

Container.defaultProps = {
  source: [],
  children: null
};
var _default = Container;
exports["default"] = _default;