"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"));

var _item = _interopRequireDefault(require("./item"));

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

;

function InfoHeader(props) {
  var title = props.title,
      status = props.status,
      extra = props.extra,
      buttons = props.buttons,
      rightExtra = props.rightExtra;

  if (title === undefined && buttons && buttons.length === 0) {
    return null;
  }

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-info-header"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-info-header-left"
  }, /*#__PURE__*/_react["default"].createElement("p", {
    className: "lp-info-header-left-name"
  }, title), /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-info-header-left-status"
  }, status)), /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-info-header-right"
  }, extra && /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-info-header-right-extra"
  }, extra), buttons && buttons.length > 0 && buttons.map(function (item, index) {
    var title = item.title;
    var className = (0, _classnames["default"])('lp-info-header-right-button', item.className);
    return /*#__PURE__*/_react["default"].createElement(_consoleComponents.Button, (0, _tslib.__assign)({
      key: 'button' + index
    }, item, {
      className: className
    }), title);
  }), rightExtra && /*#__PURE__*/_react["default"].createElement("div", {
    className: "lp-info-header-right-extra"
  }, rightExtra)));
}

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

  function Info() {
    return _super !== null && _super.apply(this, arguments) || this;
  }

  Info.prototype.render = function () {
    var _a = this.props,
        title = _a.title,
        attributes = _a.attributes,
        buttons = _a.buttons,
        extra = _a.extra,
        rightExtra = _a.rightExtra,
        status = _a.status,
        colsPerRow = _a.colsPerRow,
        locale = _a.locale,
        finishEditFunc = _a.finishEditFunc,
        onClick = _a.onClick,
        onChange = _a.onChange,
        isNest = _a.isNest,
        nest = _a.nest,
        needTitleColon = _a.needTitleColon,
        dataSource = _a.dataSource,
        className = _a.className;
    var resultAttributes = attributes;

    if (dataSource) {
      resultAttributes = attributes.map(function (item) {
        if (typeof item.convertDataFunc === "function" && item.dataIndex !== undefined) {
          item["value"] = item.convertDataFunc(dataSource[item.dataIndex]);
        } else if (item.dataIndex) {
          item["value"] = dataSource[item.dataIndex];
        } else if (!item.value) {
          item["value"] = "";
        }

        delete item.convertDataFunc;
        delete item.dataIndex;
        return item;
      });
    }

    return /*#__PURE__*/_react["default"].createElement("div", {
      style: this.props.style,
      className: (0, _classnames["default"])('lp-info', {
        'lp-nest-info': isNest !== undefined ? isNest : nest
      }, className)
    }, /*#__PURE__*/_react["default"].createElement(InfoHeader, {
      title: title,
      status: status,
      extra: extra,
      buttons: buttons,
      rightExtra: rightExtra
    }), resultAttributes && /*#__PURE__*/_react["default"].createElement("div", {
      className: "lp-info-content"
    }, resultAttributes.map(function (item, index) {
      return /*#__PURE__*/_react["default"].createElement(_item["default"], (0, _tslib.__assign)({
        key: item.name + item.value + index,
        colsPerRow: colsPerRow,
        finishEditFunc: finishEditFunc,
        onClick: onClick,
        onChange: onChange,
        locale: locale,
        needTitleColon: needTitleColon
      }, item));
    })));
  };

  return Info;
}(_react["default"].Component);

Info.defaultProps = {
  descToggle: false,
  needTitleColon: false
};
Info.Item = _item["default"];
var _default = Info;
exports["default"] = _default;