import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _extends from "@babel/runtime/helpers/esm/extends";
import { initZoomMotion } from '../../style/motion';
import { genComponentStyleHook, mergeToken, PresetColors } from '../../theme';
import { resetComponent } from '../../style/css';
import getArrowStyle from '../../style/placementArrow';

var genBaseStyle = function genBaseStyle(token) {
  var _extends2;

  var componentCls = token.componentCls,
      popoverBg = token.popoverBg,
      popoverColor = token.popoverColor,
      width = token.width,
      popoverPaddingHorizontal = token.popoverPaddingHorizontal,
      popoverTitlePaddingBlockTop = token.popoverTitlePaddingBlockTop,
      popoverTitlePaddingBlockBottom = token.popoverTitlePaddingBlockBottom,
      lineWidth = token.lineWidth,
      lineType = token.lineType,
      fontWeightStrong = token.fontWeightStrong,
      boxShadow = token.boxShadow,
      colorSplit = token.colorSplit,
      colorTextHeading = token.colorTextHeading,
      borderRadius = token.radiusBase,
      paddingSM = token.paddingSM,
      zIndexPopup = token.zIndexPopup;
  return [_defineProperty({}, componentCls, _extends(_extends({}, resetComponent(token)), (_extends2 = {
    position: 'absolute',
    top: 0,
    insetInlineStart: 0,
    zIndex: zIndexPopup,
    fontWeight: 'normal',
    whiteSpace: 'normal',
    textAlign: 'start',
    cursor: 'auto',
    userSelect: 'text',
    '&-rtl': {
      direction: 'rtl'
    },
    '&-hidden': {
      display: 'none'
    }
  }, _defineProperty(_extends2, "".concat(componentCls, "-content"), {
    position: 'relative'
  }), _defineProperty(_extends2, "".concat(componentCls, "-inner"), {
    backgroundColor: popoverBg,
    backgroundClip: 'padding-box',
    borderRadius: borderRadius,
    boxShadow: boxShadow
  }), _defineProperty(_extends2, "".concat(componentCls, "-title"), {
    minWidth: width,
    margin: 0,
    padding: "".concat(popoverTitlePaddingBlockTop, "px ").concat(popoverPaddingHorizontal, "px ").concat(popoverTitlePaddingBlockBottom, "px"),
    color: colorTextHeading,
    fontWeight: fontWeightStrong,
    borderBottom: "".concat(lineWidth, "px ").concat(lineType, " ").concat(colorSplit)
  }), _defineProperty(_extends2, "".concat(componentCls, "-inner-content"), {
    padding: "".concat(paddingSM, "px ").concat(popoverPaddingHorizontal, "px"),
    color: popoverColor
  }), _extends2))), // Arrow Style
  getArrowStyle(token, token.colorBgElevated), // Pure Render
  _defineProperty({}, "".concat(componentCls, "-pure"), _defineProperty({
    position: 'relative',
    maxWidth: 'none'
  }, "".concat(componentCls, "-content"), {
    display: 'inline-block'
  }))];
};

var genColorStyle = function genColorStyle(token) {
  var componentCls = token.componentCls;
  return _defineProperty({}, componentCls, PresetColors.map(function (colorKey) {
    var _$concat$concat;

    var lightColor = token["".concat(colorKey, "-6")];
    return _defineProperty({}, "&".concat(componentCls, "-").concat(colorKey), (_$concat$concat = {}, _defineProperty(_$concat$concat, "".concat(componentCls, "-inner"), {
      backgroundColor: lightColor
    }), _defineProperty(_$concat$concat, "".concat(componentCls, "-arrow"), {
      background: 'transparent',
      '&:before': {
        backgroundColor: lightColor
      }
    }), _$concat$concat));
  }));
};

export default genComponentStyleHook('Popover', function (token) {
  var controlHeight = token.controlHeight,
      fontSize = token.fontSize,
      lineHeight = token.lineHeight,
      lineWidth = token.lineWidth,
      colorBgElevated = token.colorBgElevated;
  var titlePaddingBlockDist = controlHeight - Math.round(fontSize * lineHeight);
  var popoverToken = mergeToken(token, {
    popoverBg: colorBgElevated,
    popoverColor: token.colorText,
    popoverTitlePaddingBlockTop: titlePaddingBlockDist / 2,
    popoverTitlePaddingBlockBottom: titlePaddingBlockDist / 2 - lineWidth,
    popoverPaddingHorizontal: token.padding
  });
  return [genBaseStyle(popoverToken), genColorStyle(popoverToken), initZoomMotion(popoverToken, 'zoom-big')];
}, function (_ref5) {
  var zIndexPopupBase = _ref5.zIndexPopupBase;
  return {
    zIndexPopup: zIndexPopupBase + 30,
    width: 177
  };
});