import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["size"],
  _excluded2 = ["size", "isTiledIcon"],
  _excluded3 = ["shape", "UNSAFE_circleReplacementComponent"];
import React from 'react';
import { IconTile } from '@atlaskit/icon';
import { fg } from '@atlaskit/platform-feature-flags';
import { SmartLinkSize } from '../../../constants';
import { isIconSizeLarge } from '../../../utils';
/**
 * Maps IconTile appearance to the icon glyph color token to use when rendering
 * a standalone icon (without a tile background).
 */
var appearanceToStandaloneIconColor = {
  blue: "var(--ds-icon-accent-blue, #357DE8)",
  blueBold: "var(--ds-icon-accent-blue, #357DE8)",
  gray: "var(--ds-icon-accent-gray, #7D818A)",
  grayBold: "var(--ds-icon-accent-gray, #7D818A)",
  green: "var(--ds-icon-accent-green, #22A06B)",
  greenBold: "var(--ds-icon-accent-green, #22A06B)",
  lime: "var(--ds-icon-accent-lime, #6A9A23)",
  limeBold: "var(--ds-icon-accent-lime, #6A9A23)",
  magenta: "var(--ds-icon-accent-magenta, #CD519D)",
  magentaBold: "var(--ds-icon-accent-magenta, #CD519D)",
  orange: "var(--ds-icon-accent-orange, #E06C00)",
  orangeBold: "var(--ds-icon-accent-orange, #E06C00)",
  purple: "var(--ds-icon-accent-purple, #AF59E1)",
  purpleBold: "var(--ds-icon-accent-purple, #AF59E1)",
  red: "var(--ds-icon-accent-red, #C9372C)",
  redBold: "var(--ds-icon-accent-red, #C9372C)",
  teal: "var(--ds-icon-accent-teal, #2898BD)",
  tealBold: "var(--ds-icon-accent-teal, #2898BD)",
  yellow: "var(--ds-icon-accent-yellow, #B38600)",
  yellowBold: "var(--ds-icon-accent-yellow, #B38600)"
};

/**
 * Maps a SmartLinkSize to an IconTileSize, or undefined if the size is too
 * small to render as a tile (e.g. SmartLinkSize.Small / Medium, or no size).
 * When undefined is returned, the caller should render the icon directly
 * without a tile.
 */
export var transformSmartLinkSizeToIconTileSize = function transformSmartLinkSizeToIconTileSize(size) {
  if (fg('platform_sl_icons_refactor')) {
    switch (size) {
      case SmartLinkSize.Small:
      case SmartLinkSize.Medium:
        return undefined;
      case SmartLinkSize.XLarge:
      case SmartLinkSize.Large:
        return 'small';
      default:
        return undefined;
    }
  }
  switch (size) {
    case SmartLinkSize.XLarge:
    case SmartLinkSize.Large:
      return 'small';
    default:
      // SmartLinkSize.Small, SmartLinkSize.Medium, and undefined all
      // previously mapped to size="16" which has been removed. Render
      // the icon directly (no tile) for these sizes.
      return undefined;
  }
};

/**
 * For large/xlarge smart-link icon size, renders an `@atlaskit/object/tile/*` component; otherwise a standard `@atlaskit/object` glyph.
 */
export var renderIconPerSize = function renderIconPerSize(ObjectIcon, ObjectTileIcon) {
  return function (_ref) {
    var size = _ref.size,
      props = _objectWithoutProperties(_ref, _excluded);
    if (isIconSizeLarge(size)) {
      return /*#__PURE__*/React.createElement(ObjectTileIcon, _extends({}, props, {
        size: "small"
      }));
    }
    return /*#__PURE__*/React.createElement(ObjectIcon, props);
  };
};
export var renderIconTile = function renderIconTile(Icon, appearance) {
  return function (_ref2) {
    var size = _ref2.size,
      isTiledIcon = _ref2.isTiledIcon,
      props = _objectWithoutProperties(_ref2, _excluded2);
    var tileSize = transformSmartLinkSizeToIconTileSize(size);
    if (tileSize === undefined) {
      var _props$label;
      // size="16" has been removed — render the icon directly without a tile,
      // using the appearance-derived color so it still matches the intended style.
      var label = (_props$label = props.label) !== null && _props$label !== void 0 ? _props$label : '';
      return /*#__PURE__*/React.createElement("span", {
        role: label ? 'img' : undefined,
        "aria-label": label || undefined,
        "data-testid": props.testId
      }, /*#__PURE__*/React.createElement(Icon, {
        color: appearanceToStandaloneIconColor[appearance],
        label: ""
      }));
    }
    var _shape = props.shape,
      _unsafe = props.UNSAFE_circleReplacementComponent,
      tileProps = _objectWithoutProperties(props, _excluded3);
    return /*#__PURE__*/React.createElement(IconTile, _extends({
      appearance: appearance,
      icon: isTiledIcon ? function (iconProps) {
        return /*#__PURE__*/React.createElement(Icon, _extends({}, iconProps, {
          spacing: "spacious"
        }));
      } : Icon,
      size: tileSize
    }, tileProps));
  };
};