"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.customOnRamp = customOnRamp;
exports.Root = exports.Text = exports.ActionIcon = exports.Action = void 0;

var _polished = require("polished");

var _index = require("../styles/index.js");

var _constants = require("./constants.js");

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function customOnRamp(color, unit) {
  switch (unit) {
    case '50':
      return (0, _polished.lighten)(0.4, color);

    case '100':
      return (0, _polished.lighten)(0.32, color);

    case '200':
      return (0, _polished.lighten)(0.2, color);

    case '300':
      return (0, _polished.lighten)(0.12, color);

    case '500':
      return (0, _polished.darken)(0.24, color);

    case '600':
      return (0, _polished.darken)(0.3, color);

    case '700':
      return (0, _polished.darken)(0.4, color);

    case '400':
    default:
      return color;
  }
}

function fontColor(props, isHovered, isActionText) {
  if (props.$disabled) {
    switch (props.$kind) {
      case _constants.KIND.neutral:
        return props.$theme.colors.tagNeutralFontDisabled;

      case _constants.KIND.positive:
        return props.$theme.colors.tagPositiveFontDisabled;

      case _constants.KIND.warning:
        return props.$theme.colors.tagWarningFontDisabled;

      case _constants.KIND.negative:
        return props.$theme.colors.tagNegativeFontDisabled;

      case _constants.KIND.custom:
        return customOnRamp(props.$color, props.$theme.colors.tagFontDisabledRampUnit);

      case _constants.KIND.primary:
      default:
        return props.$theme.colors.tagPrimaryFontDisabled;
    }
  }

  switch (props.$variant) {
    case _constants.VARIANT.solid:
      switch (props.$kind) {
        case _constants.KIND.neutral:
          if (!isHovered) return props.$theme.colors.tagNeutralSolidFont;
          return props.$theme.colors.tagNeutralSolidFontHover;

        case _constants.KIND.positive:
          if (!isHovered) return props.$theme.colors.tagPositiveSolidFont;
          return props.$theme.colors.tagPositiveSolidFontHover;

        case _constants.KIND.warning:
          if (!isHovered) return props.$theme.colors.tagWarningSolidFont;
          return props.$theme.colors.tagWarningSolidFontHover;

        case _constants.KIND.negative:
          if (!isHovered) return props.$theme.colors.tagNegativeSolidFont;
          return props.$theme.colors.tagNegativeSolidFontHover;

        case _constants.KIND.custom:
          if (!isHovered) return customOnRamp(props.$color, props.$theme.colors.tagSolidFontRampUnit);
          return customOnRamp(props.$color, props.$theme.colors.tagSolidFontHoverRampUnit);

        case _constants.KIND.primary:
        default:
          if (!isHovered) return props.$theme.colors.tagPrimarySolidFont;
          return props.$theme.colors.tagPrimarySolidFontHover;
      }

    case _constants.VARIANT.outlined:
      switch (props.$kind) {
        case _constants.KIND.neutral:
          if (!isHovered || !isActionText) {
            return props.$theme.colors.tagNeutralOutlinedFont;
          }

          return props.$theme.colors.tagNeutralOutlinedFontHover;

        case _constants.KIND.positive:
          if (!isHovered || !isActionText) {
            return props.$theme.colors.tagPositiveOutlinedFont;
          }

          return props.$theme.colors.tagPositiveOutlinedFontHover;

        case _constants.KIND.warning:
          if (!isHovered || !isActionText) {
            return props.$theme.colors.tagWarningOutlinedFont;
          }

          return props.$theme.colors.tagWarningOutlinedFontHover;

        case _constants.KIND.negative:
          if (!isHovered || !isActionText) {
            return props.$theme.colors.tagNegativeOutlinedFont;
          }

          return props.$theme.colors.tagNegativeOutlinedFontHover;

        case _constants.KIND.custom:
          if (!isHovered || !isActionText) {
            return customOnRamp(props.$color, props.$theme.colors.tagOutlinedFontRampUnit);
          }

          return customOnRamp(props.$color, props.$theme.colors.tagOutlinedFontHoverRampUnit);

        case _constants.KIND.primary:
        default:
          if (!isHovered || !isActionText) {
            return props.$theme.colors.tagPrimaryOutlinedFont;
          }

          return props.$theme.colors.tagPrimaryOutlinedFontHover;
      }

    case _constants.VARIANT.light:
    default:
      switch (props.$kind) {
        case _constants.KIND.neutral:
          if (!isHovered) return props.$theme.colors.tagNeutralLightFont;
          return props.$theme.colors.tagNeutralLightFontHover;

        case _constants.KIND.positive:
          if (!isHovered) return props.$theme.colors.tagPositiveLightFont;
          return props.$theme.colors.tagPositiveLightFontHover;

        case _constants.KIND.warning:
          if (!isHovered) return props.$theme.colors.tagWarningLightFont;
          return props.$theme.colors.tagWarningLightFontHover;

        case _constants.KIND.negative:
          if (!isHovered) return props.$theme.colors.tagNegativeLightFont;
          return props.$theme.colors.tagNegativeLightFontHover;

        case _constants.KIND.custom:
          if (!isHovered) return customOnRamp(props.$color, props.$theme.colors.tagLightFontRampUnit);
          return customOnRamp(props.$color, props.$theme.colors.tagLightFontHoverRampUnit);

        case _constants.KIND.primary:
        default:
          if (!isHovered) return props.$theme.colors.tagPrimaryLightFont;
          return props.$theme.colors.tagPrimaryLightFontHover;
      }

  }
} // $FlowFixMe https://github.com/facebook/flow/issues/7745


var Action = (0, _index.styled)('span', function (props) {
  var $disabled = props.$disabled,
      $variant = props.$variant,
      $theme = props.$theme;

  function backgroundColor(isHovered, isActive) {
    if (props.$disabled || !isHovered) return 'transparent';

    switch (props.$variant) {
      case _constants.VARIANT.solid:
        switch (props.$kind) {
          case _constants.KIND.neutral:
            return props.$theme.colors.tagNeutralSolidActive;

          case _constants.KIND.positive:
            return props.$theme.colors.tagPositiveSolidActive;

          case _constants.KIND.warning:
            return props.$theme.colors.tagWarningSolidActive;

          case _constants.KIND.negative:
            return props.$theme.colors.tagNegativeSolidActive;

          case _constants.KIND.custom:
            return customOnRamp(props.$color, props.$theme.colors.tagSolidActiveRampUnit);

          case _constants.KIND.primary:
          default:
            return props.$theme.colors.tagPrimarySolidActive;
        }

      case _constants.VARIANT.outlined:
        switch (props.$kind) {
          case _constants.KIND.neutral:
            if (!isActive) return props.$theme.colors.tagNeutralOutlinedHover;
            return props.$theme.colors.tagNeutralOutlinedActive;

          case _constants.KIND.positive:
            if (!isActive) return props.$theme.colors.tagPositiveOutlinedHover;
            return props.$theme.colors.tagPositiveOutlinedActive;

          case _constants.KIND.warning:
            if (!isActive) return props.$theme.colors.tagWarningOutlinedHover;
            return props.$theme.colors.tagWarningOutlinedActive;

          case _constants.KIND.negative:
            if (!isActive) return props.$theme.colors.tagNegativeOutlinedHover;
            return props.$theme.colors.tagNegativeOutlinedActive;

          case _constants.KIND.custom:
            if (!isActive) return customOnRamp(props.$color, props.$theme.colors.tagOutlinedHoverRampUnit);
            return customOnRamp(props.$color, props.$theme.colors.tagOutlinedActiveRampUnit);

          case _constants.KIND.primary:
          default:
            if (!isActive) return props.$theme.colors.tagPrimaryOutlinedHover;
            return props.$theme.colors.tagPrimaryOutlinedActive;
        }

      case _constants.VARIANT.light:
      default:
        switch (props.$kind) {
          case _constants.KIND.neutral:
            return props.$theme.colors.tagNeutralLightActive;

          case _constants.KIND.positive:
            return props.$theme.colors.tagPositiveLightActive;

          case _constants.KIND.warning:
            return props.$theme.colors.tagWarningLightActive;

          case _constants.KIND.negative:
            return props.$theme.colors.tagNegativeLightActive;

          case _constants.KIND.custom:
            return customOnRamp(props.$color, props.$theme.colors.tagLightActiveRampUnit);

          case _constants.KIND.primary:
          default:
            return props.$theme.colors.tagPrimaryLightActive;
        }

    }
  }

  return {
    alignItems: 'center',
    borderBottomRightRadius: $theme.borders.useRoundedCorners ? $theme.borders.radius400 : 0,
    borderTopRightRadius: $theme.borders.useRoundedCorners ? $theme.borders.radius400 : 0,
    cursor: $disabled ? 'not-allowed' : 'pointer',
    display: 'flex',
    marginLeft: '8px',
    outline: 'none',
    paddingTop: $variant === _constants.VARIANT.outlined ? '5px' : '7px',
    paddingBottom: $variant === _constants.VARIANT.outlined ? '5px' : '7px',
    paddingLeft: '8px',
    paddingRight: '8px',
    transitionProperty: 'all',
    transitionDuration: $theme.animation.timing100,
    transitionTimingFunction: $theme.animation.easeOutCurve,
    ':hover': {
      backgroundColor: backgroundColor(true, false),
      color: fontColor(props, true, true)
    },
    ':focus': {
      backgroundColor: backgroundColor(true, false),
      color: fontColor(props, true, true)
    }
  };
});
exports.Action = Action;
Action.displayName = "Action";
var ActionIcon = (0, _index.styled)('svg', {}); // $FlowFixMe https://github.com/facebook/flow/issues/7745

exports.ActionIcon = ActionIcon;
ActionIcon.displayName = "ActionIcon";
var Text = (0, _index.styled)('span', function (props) {
  return {
    overflow: 'hidden',
    whiteSpace: 'nowrap',
    textOverflow: 'ellipsis',
    maxWidth: props.$theme.sizing.scale3200
  };
}); // $FlowFixMe https://github.com/facebook/flow/issues/7745

exports.Text = Text;
Text.displayName = "Text";
var Root = (0, _index.styled)('span', function (props) {
  var $disabled = props.$disabled,
      $theme = props.$theme,
      $closeable = props.$closeable,
      $clickable = props.$clickable,
      $kind = props.$kind,
      $variant = props.$variant;
  var _$theme$sizing = $theme.sizing,
      scale0 = _$theme$sizing.scale0,
      scale800 = _$theme$sizing.scale800,
      scale500 = _$theme$sizing.scale500,
      font250 = $theme.typography.font250;

  function backgroundColor(isHovered, isActive) {
    if (props.$variant === _constants.VARIANT.outlined) {
      return 'transparent';
    }

    switch ($variant) {
      case _constants.VARIANT.solid:
        switch ($kind) {
          case _constants.KIND.neutral:
            if ($disabled) {
              return props.$theme.colors.tagNeutralSolidDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagNeutralSolidActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagNeutralSolidHover;
            }

            return props.$theme.colors.tagNeutralSolidBackground;

          case _constants.KIND.positive:
            if ($disabled) {
              return props.$theme.colors.tagPositiveSolidDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagPositiveSolidActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagPositiveSolidHover;
            }

            return props.$theme.colors.tagPositiveSolidBackground;

          case _constants.KIND.warning:
            if ($disabled) {
              return props.$theme.colors.tagWarningSolidDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagWarningSolidActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagWarningSolidHover;
            }

            return props.$theme.colors.tagWarningSolidBackground;

          case _constants.KIND.negative:
            if ($disabled) {
              return props.$theme.colors.tagNegativeSolidDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagNegativeSolidActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagNegativeSolidHover;
            }

            return props.$theme.colors.tagNegativeSolidBackground;

          case _constants.KIND.custom:
            if ($disabled) {
              return customOnRamp(props.$color, props.$theme.colors.tagSolidDisabledRampUnit);
            }

            if (isActive) {
              return customOnRamp(props.$color, props.$theme.colors.tagSolidActiveRampUnit);
            }

            if (isHovered) {
              return customOnRamp(props.$color, props.$theme.colors.tagSolidHoverRampUnit);
            }

            return customOnRamp(props.$color, props.$theme.colors.tagSolidRampUnit);

          case _constants.KIND.primary:
          default:
            if ($disabled) {
              return props.$theme.colors.tagPrimarySolidDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagPrimarySolidActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagPrimarySolidHover;
            }

            return props.$theme.colors.tagPrimarySolidBackground;
        }

      case _constants.VARIANT.light:
      default:
        switch ($kind) {
          case _constants.KIND.neutral:
            if ($disabled) {
              return props.$theme.colors.tagNeutralLightDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagNeutralLightActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagNeutralLightHover;
            }

            return props.$theme.colors.tagNeutralLightBackground;

          case _constants.KIND.positive:
            if ($disabled) {
              return props.$theme.colors.tagPositiveLightDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagPositiveLightActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagPositiveLightHover;
            }

            return props.$theme.colors.tagPositiveLightBackground;

          case _constants.KIND.warning:
            if ($disabled) {
              return props.$theme.colors.tagWarningLightDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagWarningLightActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagWarningLightHover;
            }

            return props.$theme.colors.tagWarningLightBackground;

          case _constants.KIND.negative:
            if ($disabled) {
              return props.$theme.colors.tagNegativeLightDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagNegativeLightActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagNegativeLightHover;
            }

            return props.$theme.colors.tagNegativeLightBackground;

          case _constants.KIND.custom:
            if ($disabled) {
              return customOnRamp(props.$color, props.$theme.colors.tagLightRampUnit);
            }

            if (isActive) {
              return customOnRamp(props.$color, props.$theme.colors.tagLightActiveRampUnit);
            }

            if (isHovered) {
              return customOnRamp(props.$color, props.$theme.colors.tagLightHoverRampUnit);
            }

            return customOnRamp(props.$color, props.$theme.colors.tagLightRampUnit);

          case _constants.KIND.primary:
          default:
            if ($disabled) {
              return props.$theme.colors.tagPrimaryLightDisabled;
            }

            if (isActive) {
              return props.$theme.colors.tagPrimaryLightActive;
            }

            if (isHovered) {
              return props.$theme.colors.tagPrimaryLightHover;
            }

            return props.$theme.colors.tagPrimaryLightBackground;
        }

    }
  }

  function borderColor(isHovered, isActive) {
    if (props.$variant !== _constants.VARIANT.outlined) {
      return null;
    }

    switch (props.$kind) {
      case _constants.KIND.neutral:
        if ($disabled) {
          return props.$theme.colors.tagNeutralOutlinedDisabled;
        }

        if (isActive) {
          return props.$theme.colors.tagNeutralOutlinedActive;
        }

        if (isHovered) {
          return props.$theme.colors.tagNeutralOutlinedHover;
        }

        return props.$theme.colors.tagNeutralOutlinedBackground;

      case _constants.KIND.positive:
        if ($disabled) {
          return props.$theme.colors.tagPositiveOutlinedDisabled;
        }

        if (isActive) {
          return props.$theme.colors.tagPositiveOutlinedActive;
        }

        if (isHovered) {
          return props.$theme.colors.tagPositiveOutlinedHover;
        }

        return props.$theme.colors.tagPositiveOutlinedBackground;

      case _constants.KIND.warning:
        if ($disabled) {
          return props.$theme.colors.tagWarningOutlinedDisabled;
        }

        if (isActive) {
          return props.$theme.colors.tagWarningOutlinedActive;
        }

        if (isHovered) {
          return props.$theme.colors.tagWarningOutlinedHover;
        }

        return props.$theme.colors.tagWarningOutlinedBackground;

      case _constants.KIND.negative:
        if ($disabled) {
          return props.$theme.colors.tagNegativeOutlinedDisabled;
        }

        if (isActive) {
          return props.$theme.colors.tagNegativeOutlinedActive;
        }

        if (isHovered) {
          return props.$theme.colors.tagNegativeOutlinedHover;
        }

        return props.$theme.colors.tagNegativeOutlinedBackground;

      case _constants.KIND.custom:
        if ($disabled) {
          return customOnRamp(props.$color, props.$theme.colors.tagOutlinedRampUnit);
        }

        if (isActive) {
          return customOnRamp(props.$color, props.$theme.colors.tagOutlinedActiveRampUnit);
        }

        if (isHovered) {
          return customOnRamp(props.$color, props.$theme.colors.tagOutlinedHoverRampUnit);
        }

        return customOnRamp(props.$color, props.$theme.colors.tagOutlinedRampUnit);

      case _constants.KIND.primary:
      default:
        if ($disabled) {
          return props.$theme.colors.tagPrimaryOutlinedDisabled;
        }

        if (isActive) {
          return props.$theme.colors.tagPrimaryOutlinedActive;
        }

        if (isHovered) {
          return props.$theme.colors.tagPrimaryOutlinedHover;
        }

        return props.$theme.colors.tagPrimaryOutlinedBackground;
    }
  }

  var borderRadius = $theme.borders.useRoundedCorners ? $theme.borders.radius400 : 0;
  return _objectSpread({}, font250, {
    alignItems: 'center',
    backgroundColor: backgroundColor(false, false),
    borderColor: borderColor(false, false),
    borderStyle: 'solid',
    borderWidth: $variant === _constants.VARIANT.outlined ? '2px' : 0,
    borderTopLeftRadius: borderRadius,
    borderTopRightRadius: borderRadius,
    borderBottomRightRadius: borderRadius,
    borderBottomLeftRadius: borderRadius,
    boxSizing: 'border-box',
    color: fontColor(props, false, false),
    cursor: $disabled ? 'not-allowed' : $clickable ? 'pointer' : 'default',
    display: 'inline-flex',
    height: scale800,
    justifyContent: 'space-between',
    marginTop: '5px',
    marginBottom: '5px',
    marginLeft: '5px',
    marginRight: '5px',
    paddingTop: scale0,
    paddingBottom: scale0,
    paddingLeft: scale500,
    paddingRight: $closeable ? null : scale500,
    outline: 'none',
    ':hover': $disabled || !$clickable ? {} : {
      backgroundColor: backgroundColor(true, false),
      borderColor: borderColor(true, false),
      color: fontColor(props, true, false)
    },
    ':focus': $disabled || !$clickable ? {} : {
      backgroundColor: backgroundColor(true, true),
      borderColor: borderColor(true, true),
      color: fontColor(props, true, false)
    }
  });
});
exports.Root = Root;
Root.displayName = "Root";