"use strict";

import React, { memo, useMemo } from 'react';
import { View, Text } from 'react-native';
import { useTheme } from "../theme/use-theme.js";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
const SIZE_CONFIG = {
  small: {
    minWidth: 16,
    height: 16,
    fontSize: 10,
    paddingHorizontal: 4,
    dotSize: 6
  },
  medium: {
    minWidth: 20,
    height: 20,
    fontSize: 12,
    paddingHorizontal: 6,
    dotSize: 8
  },
  large: {
    minWidth: 24,
    height: 24,
    fontSize: 14,
    paddingHorizontal: 8,
    dotSize: 10
  }
};
const PLACEMENT_CONFIG = {
  'top-right': {
    top: -4,
    right: -4
  },
  'top-left': {
    top: -4,
    left: -4
  },
  'bottom-right': {
    bottom: -4,
    right: -4
  },
  'bottom-left': {
    bottom: -4,
    left: -4
  }
};
function useColorPair(color, variant, theme) {
  const colorMap = {
    default: theme.colors.textSecondary,
    primary: theme.colors.primary,
    success: theme.colors.success,
    warning: theme.colors.warning,
    error: theme.colors.error,
    info: theme.colors.info
  };
  const base = colorMap[color];
  // A primary-colored solid badge needs the preset's readable foreground
  // (white for blue, black for yellow). Semantic colors are fixed bright
  // fills that always pair with white.
  const solidForeground = base === theme.colors.primary ? theme.colors.primaryForeground : '#fff';
  switch (variant) {
    case 'solid':
      return {
        bg: base,
        fg: solidForeground
      };
    case 'subtle':
      return {
        bg: base + '20',
        fg: base
      };
    case 'outlined':
      return {
        bg: 'transparent',
        fg: base
      };
  }
}
const BadgeComponent = ({
  content,
  variant = 'solid',
  color = 'error',
  size = 'medium',
  dot = false,
  max,
  invisible = false,
  placement = 'top-right',
  children,
  style,
  textStyle,
  testID
}) => {
  const theme = useTheme();
  const colors = useColorPair(color, variant, theme);
  const sizeConfig = SIZE_CONFIG[size];
  const displayContent = useMemo(() => {
    if (dot) return null;
    if (content == null) return null;
    if (typeof content === 'number' && max != null && content > max) {
      return `${max}+`;
    }
    return String(content);
  }, [content, dot, max]);
  const badgeStyle = useMemo(() => {
    if (dot) {
      return {
        width: sizeConfig.dotSize,
        height: sizeConfig.dotSize,
        borderRadius: sizeConfig.dotSize / 2,
        backgroundColor: colors.bg
      };
    }
    const base = {
      minWidth: sizeConfig.height,
      height: sizeConfig.height,
      borderRadius: sizeConfig.height / 2,
      paddingHorizontal: sizeConfig.paddingHorizontal,
      backgroundColor: colors.bg,
      alignItems: 'center',
      justifyContent: 'center'
    };
    if (variant === 'outlined') {
      base.borderWidth = 1;
      base.borderColor = colors.fg;
    }
    return base;
  }, [dot, sizeConfig, colors, variant]);
  const badgeTextStyle = useMemo(() => ({
    fontSize: sizeConfig.fontSize,
    fontWeight: '600',
    color: colors.fg,
    textAlign: 'center',
    lineHeight: sizeConfig.height
  }), [sizeConfig, colors]);

  // Standalone badge (no children)
  if (!children) {
    if (invisible) return null;
    return /*#__PURE__*/_jsx(View, {
      style: [badgeStyle, style],
      testID: testID,
      children: displayContent != null && /*#__PURE__*/_jsx(Text, {
        style: [badgeTextStyle, textStyle],
        children: displayContent
      })
    });
  }

  // Positioned badge wrapping children
  return /*#__PURE__*/_jsxs(View, {
    style: {
      position: 'relative',
      alignSelf: 'flex-start'
    },
    testID: testID,
    children: [children, !invisible && /*#__PURE__*/_jsx(View, {
      style: [{
        position: 'absolute',
        zIndex: 1,
        ...PLACEMENT_CONFIG[placement]
      }, badgeStyle, style],
      children: displayContent != null && /*#__PURE__*/_jsx(Text, {
        style: [badgeTextStyle, textStyle],
        children: displayContent
      })
    })]
  });
};
export const Badge = /*#__PURE__*/memo(BadgeComponent);
Badge.displayName = 'Badge';
//# sourceMappingURL=Badge.js.map