"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _components = require("@alicloudfe/components");
var _react = _interopRequireDefault(require("react"));
var _ProInfoItem = _interopRequireDefault(require("../ProInfoItem"));
require("./index.scss");
var _utils = require("../../utils/utils");
var _layout = _interopRequireDefault(require("../../utils/layout"));
var _InfoValueItem = _interopRequireDefault(require("../InfoValueItem"));
var _utils2 = require("../../utils");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Row = _components.Grid.Row,
  Col = _components.Grid.Col;
var ProBaseInfo = function ProBaseInfo(props) {
  var _size$width;
  var columns = props.columns,
    dataSource = props.dataSource,
    loading = props.loading,
    result = props.result,
    actionRef = props.actionRef,
    layout = props.layout,
    size = props.size,
    context = props.context;
  var defaultLayout = _layout.default[(0, _utils.getLayout)((_size$width = size === null || size === void 0 ? void 0 : size.width) !== null && _size$width !== void 0 ? _size$width : 0)];
  // 获取列内的布局参数
  var getFormItemLayout = function getFormItemLayout(colspan) {
    var formItemLayout = JSON.parse(JSON.stringify(defaultLayout.formItemLayout));
    // 自定义布局
    if (layout) {
      var _layout$labelCol, _layout$wrapperCol;
      var labelCol = (_layout$labelCol = layout === null || layout === void 0 ? void 0 : layout.labelCol) !== null && _layout$labelCol !== void 0 ? _layout$labelCol : defaultLayout.formItemLayout.labelCol;
      var wrapperCol = (_layout$wrapperCol = layout === null || layout === void 0 ? void 0 : layout.wrapperCol) !== null && _layout$wrapperCol !== void 0 ? _layout$wrapperCol : defaultLayout.formItemLayout.wrapperCol;
      formItemLayout.labelCol = labelCol;
      formItemLayout.wrapperCol = wrapperCol;
    }
    var newLabelSpan = formItemLayout.labelCol.span;
    var newWrapperSpan = formItemLayout.wrapperCol.span;
    // 计算合并列情况。label与wrapper需要重新计算
    if (colspan) {
      var _layout$span, _layout$span2;
      var realColspan = ((_layout$span = layout === null || layout === void 0 ? void 0 : layout.span) !== null && _layout$span !== void 0 ? _layout$span : 24 / defaultLayout.span > colspan) ? colspan : (_layout$span2 = layout === null || layout === void 0 ? void 0 : layout.span) !== null && _layout$span2 !== void 0 ? _layout$span2 : 24 / defaultLayout.span;
      newLabelSpan = newLabelSpan / realColspan;
      newWrapperSpan = newWrapperSpan + (formItemLayout.labelCol.span - newLabelSpan);
    }
    var newFormItemLayout = {
      labelCol: {
        span: newLabelSpan.toFixed()
      },
      wrapperCol: {
        span: newWrapperSpan.toFixed()
      }
    };
    return Object.assign(formItemLayout, newFormItemLayout);
  };
  var renderContent = function renderContent() {
    return columns.map(function (item, index) {
      var _ref, _ref2, _layout$span3, _layout$span4, _item$title, _item$valueType, _ref3, _item$colSpan;
      var hidden = (0, _utils2.isHidden)(item === null || item === void 0 ? void 0 : item.hidden, (0, _utils2.getDataIndexValue)(item.dataIndex, (_ref = dataSource !== null && dataSource !== void 0 ? dataSource : result) !== null && _ref !== void 0 ? _ref : {}), (_ref2 = dataSource !== null && dataSource !== void 0 ? dataSource : result) !== null && _ref2 !== void 0 ? _ref2 : {}, context);
      if (hidden) {
        return;
      }
      var span = item.colSpan ? defaultLayout.span : defaultLayout.span;
      var layoutSpan = item.colSpan ? ((_layout$span3 = layout === null || layout === void 0 ? void 0 : layout.span) !== null && _layout$span3 !== void 0 ? _layout$span3 : span) * item.colSpan : (_layout$span4 = layout === null || layout === void 0 ? void 0 : layout.span) !== null && _layout$span4 !== void 0 ? _layout$span4 : span;
      return /*#__PURE__*/_react.default.createElement(Col, {
        span: layoutSpan > 24 ? 24 : layoutSpan,
        key: index
      }, /*#__PURE__*/_react.default.createElement(_ProInfoItem.default, {
        label: (_item$title = item === null || item === void 0 ? void 0 : item.title) !== null && _item$title !== void 0 ? _item$title : '',
        loading: loading,
        value: /*#__PURE__*/_react.default.createElement(_InfoValueItem.default, {
          type: (_item$valueType = item === null || item === void 0 ? void 0 : item.valueType) !== null && _item$valueType !== void 0 ? _item$valueType : 'text',
          value: (0, _utils2.getDataIndexValue)(item.dataIndex, (_ref3 = dataSource !== null && dataSource !== void 0 ? dataSource : result) !== null && _ref3 !== void 0 ? _ref3 : {}),
          render: item.render,
          dataSource: item.dataSource,
          infoItem: item,
          record: dataSource !== null && dataSource !== void 0 ? dataSource : result,
          actionRef: actionRef,
          context: context,
          props: item.props
        }),
        baseInfoLayout: getFormItemLayout((_item$colSpan = item === null || item === void 0 ? void 0 : item.colSpan) !== null && _item$colSpan !== void 0 ? _item$colSpan : 0),
        tooltip: item.tooltip,
        tooltipIcon: item.tooltipIcon,
        render: item.render,
        valueType: item.valueType,
        alignItems: item.alignItems
      }));
    });
  };
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, (size === null || size === void 0 ? void 0 : size.width) && /*#__PURE__*/_react.default.createElement(Row, {
    wrap: true,
    className: "teamix-pro-info-content-row",
    gutter: 20
  }, renderContent()));
};
var _default = ProBaseInfo;
exports.default = _default;