import _extends from "@babel/runtime-corejs3/helpers/extends";
import _taggedTemplateLiteral from "@babel/runtime-corejs3/helpers/taggedTemplateLiteral";

var _templateObject;

import React from 'react';
import styled from 'styled-components';
import { icons } from '../../common-views';
import { internals } from '../../internals';
import { makeRecursiveMapper } from '../../utils';
var HeaderCellWithTips = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n  display: flex;\n  align-items: center;\n\n  .tip-icon-wrapper {\n    margin-left: 2px;\n  }\n\n  .tip-icon {\n    display: flex;\n    fill: currentColor;\n  }\n"])));
export function tips() {
  return function tipsSteap(pipeline) {
    var Balloon = pipeline.ctx.components.Balloon;
    var Tooltip = pipeline.ctx.components.Tooltip;

    if (Balloon == null && Tooltip == null) {
      throw new Error('使用 tips 之前需要通过 pipeline context 设置 components.Balloon / components.Tooltip');
    }

    return pipeline.mapColumns(makeRecursiveMapper(function (col) {
      var _a;

      if (!((_a = col.features) === null || _a === void 0 ? void 0 : _a.tips)) {
        return col;
      }

      var justifyContent = col.align === 'right' ? 'flex-end' : col.align === 'center' ? 'center' : 'flex-start';
      return _extends(_extends({}, col), {
        title: /*#__PURE__*/React.createElement(HeaderCellWithTips, {
          style: {
            justifyContent: justifyContent
          }
        }, internals.safeRenderHeader(col), Balloon ?
        /*#__PURE__*/
        // fusion/hippo
        React.createElement(Balloon, {
          closable: false,
          trigger: /*#__PURE__*/React.createElement("div", {
            className: "tip-icon-wrapper"
          }, /*#__PURE__*/React.createElement(icons.Info, {
            className: "tip-icon"
          }))
        }, col.features.tips) :
        /*#__PURE__*/
        // antd
        React.createElement(Tooltip, {
          title: col.features.tips
        }, /*#__PURE__*/React.createElement("div", {
          className: "tip-icon-wrapper"
        }, /*#__PURE__*/React.createElement(icons.Info, {
          className: "tip-icon"
        }))))
      });
    }));
  };
}