import { Grid } from '@alicloudfe/components';
import React from 'react';
import ProInfoItem from '../ProInfoItem';
import './index.scss';
import defaultLayoutMap from '../../utils/layout';
import { getLayout } from '../../utils/utils';
import InfoValueItem from '../InfoValueItem';
import { getDataIndexValue, isHidden } from '../../utils';
var Row = Grid.Row,
  Col = 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 = defaultLayoutMap[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 = isHidden(item === null || item === void 0 ? void 0 : item.hidden, 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.createElement(Col, {
        span: span,
        key: index
      }, /*#__PURE__*/React.createElement(ProInfoItem, {
        label: (_item$title = item === null || item === void 0 ? void 0 : item.title) !== null && _item$title !== void 0 ? _item$title : '',
        loading: loading,
        value: /*#__PURE__*/React.createElement(InfoValueItem, {
          type: (_item$valueType = item === null || item === void 0 ? void 0 : item.valueType) !== null && _item$valueType !== void 0 ? _item$valueType : 'text',
          value: 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.createElement(React.Fragment, null, (size === null || size === void 0 ? void 0 : size.width) && /*#__PURE__*/React.createElement(Row, {
    wrap: true,
    className: "teamix-pro-info-content-row"
  }, renderContent()));
};
export default ProHeaderInfo;