"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 _layout = _interopRequireDefault(require("../../utils/layout"));

var _utils = require("../../utils/utils");

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 ProHeaderInfo = function ProHeaderInfo(props) {
  var _size$width;

  var columns = props.columns,
      dataSource = props.dataSource,
      layout = props.layout,
      loading = props.loading,
      result = props.result,
      actionRef = props.actionRef,
      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 renderContent = function renderContent() {
    return columns.map(function (item, index) {
      var _ref, _ref2, _item$title, _item$valueType;

      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 = 24;

      if (layout === null || layout === void 0 ? void 0 : layout.colNum) {
        var _item$colSpan;

        span = 24 / (layout === null || layout === void 0 ? void 0 : layout.colNum) * ((_item$colSpan = item === null || item === void 0 ? void 0 : item.colSpan) !== null && _item$colSpan !== void 0 ? _item$colSpan : 1);
      } else {
        var _item$colSpan2;

        span = defaultLayout.span * ((_item$colSpan2 = item === null || item === void 0 ? void 0 : item.colSpan) !== null && _item$colSpan2 !== void 0 ? _item$colSpan2 : 1);
      }

      return /*#__PURE__*/_react.default.createElement(Col, {
        span: span,
        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, dataSource !== null && dataSource !== void 0 ? dataSource : result),
          render: item.render,
          dataSource: item.dataSource,
          infoItem: item,
          record: dataSource !== null && dataSource !== void 0 ? dataSource : result,
          actionRef: actionRef,
          context: context,
          props: item.props
        }),
        headerInfoLayout: layout !== null && layout !== void 0 ? layout : defaultLayout,
        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"
  }, renderContent()));
};

var _default = ProHeaderInfo;
exports.default = _default;