"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Badge = void 0;
var _reactNative = require("react-native");
var _context = require("../../context");
var _core = require("../../core");
var _accessibility = require("../../utils/accessibility");
var _typography = require("../typography");
var _jsxRuntime = require("react/jsx-runtime");
const styles = _reactNative.StyleSheet.create({
  badge: {
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "center",
    overflow: "hidden",
    borderCurve: "continuous",
    ..._reactNative.Platform.select({
      android: {
        textAlignVertical: "center"
      }
    })
  },
  badgeStaticStyle: {
    borderRadius: _core.IOBadgeRadius,
    paddingHorizontal: _core.IOBadgeHSpacing,
    paddingVertical: _core.IOBadgeVSpacing
  }
});

/**
 * Official badge component
 */
const Badge = ({
  text,
  outline = false,
  allowFontScaling = true,
  variant,
  accessible = true,
  testID
}) => {
  const {
    dynamicFontScale
  } = (0, _accessibility.useIOFontDynamicScale)();
  const {
    themeType
  } = (0, _context.useIOThemeContext)();
  const bgOpacityDarkMode = 0.2;
  const mapVariantsLightMode = {
    default: {
      foreground: "blueIO-850",
      background: _core.IOColors["blueIO-50"]
    },
    warning: {
      foreground: "warning-850",
      background: _core.IOColors["warning-100"]
    },
    success: {
      foreground: "success-850",
      background: _core.IOColors["success-100"]
    },
    error: {
      foreground: "error-850",
      background: _core.IOColors["error-100"]
    },
    cgn: {
      foreground: "hanPurple-500",
      background: _core.IOColors["hanPurple-100"]
    },
    highlight: {
      foreground: "turquoise-850",
      background: _core.IOColors["turquoise-50"]
    }
  };
  const mapVariantsDarkMode = {
    default: {
      foreground: "blueIO-200",
      background: (0, _core.hexToRgba)(_core.IOColors["blueIO-200"], bgOpacityDarkMode)
    },
    warning: {
      foreground: "warning-400",
      background: (0, _core.hexToRgba)(_core.IOColors["warning-400"], bgOpacityDarkMode)
    },
    success: {
      foreground: "success-400",
      background: (0, _core.hexToRgba)(_core.IOColors["success-400"], bgOpacityDarkMode)
    },
    error: {
      foreground: "error-400",
      background: (0, _core.hexToRgba)(_core.IOColors["error-400"], bgOpacityDarkMode)
    },
    cgn: {
      foreground: "hanPurple-250",
      background: (0, _core.hexToRgba)(_core.IOColors["hanPurple-250"], bgOpacityDarkMode)
    },
    highlight: {
      foreground: "turquoise-300",
      background: (0, _core.hexToRgba)(_core.IOColors["turquoise-300"], bgOpacityDarkMode)
    }
  };
  const mapOutlineVariantsLightMode = {
    default: {
      foreground: "blueIO-850"
    },
    warning: {
      foreground: "warning-850"
    },
    success: {
      foreground: "success-850"
    },
    error: {
      foreground: "error-850"
    },
    cgn: {
      foreground: "hanPurple-500"
    },
    highlight: {
      foreground: "turquoise-850"
    }
  };
  const mapOutlineVariantsDarkMode = {
    default: {
      foreground: "blueIO-200"
    },
    warning: {
      foreground: "warning-400"
    },
    success: {
      foreground: "success-400"
    },
    error: {
      foreground: "error-400"
    },
    cgn: {
      foreground: "hanPurple-250"
    },
    highlight: {
      foreground: "turquoise-300"
    }
  };

  // prettier-ignore
  const variantMap = themeType === "light" ? outline ? mapOutlineVariantsLightMode : mapVariantsLightMode : outline ? mapOutlineVariantsDarkMode : mapVariantsDarkMode;
  const {
    background,
    foreground
  } = variantMap[variant];
  const dynamicStyle = {
    borderRadius: _core.IOBadgeRadius * dynamicFontScale,
    paddingHorizontal: _core.IOBadgeHSpacing * dynamicFontScale,
    paddingVertical: _core.IOBadgeVSpacing * dynamicFontScale
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    accessible: accessible,
    testID: testID,
    style: [styles.badge, allowFontScaling ? dynamicStyle : styles.badgeStaticStyle, outline ? {
      borderWidth: 1,
      borderColor: _core.IOColors[foreground]
    } : {
      backgroundColor: background ?? undefined
    }],
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_typography.IOText, {
      allowFontScaling: allowFontScaling,
      weight: "Semibold",
      size: 12,
      lineHeight: 16,
      color: foreground,
      numberOfLines: 1,
      ellipsizeMode: "tail",
      style: {
        alignSelf: "center",
        textTransform: "uppercase",
        letterSpacing: 0.5
      },
      children: text
    })
  });
};
exports.Badge = Badge;
//# sourceMappingURL=Badge.js.map