"use strict";

var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.tips = tips;

var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));

var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/taggedTemplateLiteral"));

var _react = _interopRequireDefault(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _commonViews = require("../../common-views");

var _internals = require("../../internals");

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

var _templateObject;

var HeaderCellWithTips = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\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"])));

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((0, _utils.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 (0, _extends2.default)((0, _extends2.default)({}, col), {
        title: /*#__PURE__*/_react.default.createElement(HeaderCellWithTips, {
          style: {
            justifyContent: justifyContent
          }
        }, _internals.internals.safeRenderHeader(col), Balloon ?
        /*#__PURE__*/
        // fusion/hippo
        _react.default.createElement(Balloon, {
          closable: false,
          trigger: /*#__PURE__*/_react.default.createElement("div", {
            className: "tip-icon-wrapper"
          }, /*#__PURE__*/_react.default.createElement(_commonViews.icons.Info, {
            className: "tip-icon"
          }))
        }, col.features.tips) :
        /*#__PURE__*/
        // antd
        _react.default.createElement(Tooltip, {
          title: col.features.tips
        }, /*#__PURE__*/_react.default.createElement("div", {
          className: "tip-icon-wrapper"
        }, /*#__PURE__*/_react.default.createElement(_commonViews.icons.Info, {
          className: "tip-icon"
        }))))
      });
    }));
  };
}