"use strict";

import React, { memo, useMemo } from 'react';
import { View, Text, Pressable, Animated } from 'react-native';
import { useTheme } from "../theme/use-theme.js";
import { usePressAnimation } from "../hooks/usePressAnimation.js";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
const SIZE_CONFIG = {
  small: {
    height: 24,
    fontSize: 12,
    paddingHorizontal: 8,
    iconGap: 4,
    iconSize: 14
  },
  medium: {
    height: 32,
    fontSize: 14,
    paddingHorizontal: 12,
    iconGap: 6,
    iconSize: 16
  },
  large: {
    height: 40,
    fontSize: 16,
    paddingHorizontal: 16,
    iconGap: 8,
    iconSize: 18
  }
};
const PRESS_SCALE = 0.95;
function useChipColors(color, variant, selected, theme) {
  const colorMap = {
    default: theme.colors.textSecondary,
    primary: theme.colors.primary,
    success: theme.colors.success,
    warning: theme.colors.warning,
    error: theme.colors.error
  };
  const base = selected ? theme.colors.primary : colorMap[color];
  // When the background is the theme primary, the readable text/icon color is
  // preset-specific (white for blue, black for yellow). Semantic colors
  // (success/warning/error) are fixed bright fills that always pair with white.
  const isPrimaryBg = base === theme.colors.primary;
  const solidForeground = isPrimaryBg ? theme.colors.primaryForeground : '#fff';
  switch (variant) {
    case 'solid':
      return {
        bg: base,
        fg: solidForeground,
        border: base
      };
    case 'outlined':
      return {
        bg: 'transparent',
        fg: base,
        border: base
      };
    case 'soft':
      return {
        bg: base + '18',
        fg: base,
        border: 'transparent'
      };
  }
}
const ChipComponent = ({
  children,
  variant = 'outlined',
  color = 'default',
  size = 'medium',
  startIcon,
  endIcon,
  onPress,
  onClose,
  selected = false,
  disabled = false,
  style,
  textStyle,
  accessibilityLabel,
  testID
}) => {
  const theme = useTheme();
  const {
    scaleAnim,
    onPressIn,
    onPressOut
  } = usePressAnimation(PRESS_SCALE);
  const colors = useChipColors(color, variant, selected, theme);
  const sizeConfig = SIZE_CONFIG[size];
  const containerStyle = useMemo(() => ({
    height: sizeConfig.height,
    borderRadius: sizeConfig.height / 2,
    paddingHorizontal: sizeConfig.paddingHorizontal,
    backgroundColor: colors.bg,
    borderWidth: variant === 'outlined' ? 1 : 0,
    borderColor: colors.border,
    flexDirection: 'row',
    alignItems: 'center',
    gap: sizeConfig.iconGap,
    alignSelf: 'flex-start'
  }), [sizeConfig, colors, variant]);
  const labelStyle = useMemo(() => ({
    fontSize: sizeConfig.fontSize,
    fontWeight: '500',
    color: colors.fg
  }), [sizeConfig, colors]);
  const closeButton = onClose ? /*#__PURE__*/_jsx(Pressable, {
    onPress: onClose,
    hitSlop: {
      top: 6,
      bottom: 6,
      left: 6,
      right: 6
    },
    accessibilityLabel: "Remove",
    accessibilityRole: "button",
    children: /*#__PURE__*/_jsx(Text, {
      style: {
        fontSize: sizeConfig.iconSize,
        color: colors.fg,
        lineHeight: sizeConfig.iconSize
      },
      children: '\u00D7'
    })
  }) : null;
  const content = /*#__PURE__*/_jsxs(_Fragment, {
    children: [startIcon, typeof children === 'string' ? /*#__PURE__*/_jsx(Text, {
      style: [labelStyle, textStyle],
      children: children
    }) : children, endIcon, closeButton]
  });
  if (onPress) {
    return /*#__PURE__*/_jsx(Animated.View, {
      style: {
        transform: [{
          scale: scaleAnim
        }]
      },
      children: /*#__PURE__*/_jsx(Pressable, {
        style: [containerStyle, disabled && {
          opacity: 0.5
        }, style],
        onPress: onPress,
        onPressIn: onPressIn,
        onPressOut: onPressOut,
        disabled: disabled,
        accessibilityLabel: accessibilityLabel,
        accessibilityRole: "button",
        accessibilityState: {
          disabled,
          selected
        },
        testID: testID,
        children: content
      })
    });
  }
  return /*#__PURE__*/_jsx(View, {
    style: [containerStyle, disabled && {
      opacity: 0.5
    }, style],
    accessibilityLabel: accessibilityLabel,
    testID: testID,
    children: content
  });
};
export const Chip = /*#__PURE__*/memo(ChipComponent);
Chip.displayName = 'Chip';
//# sourceMappingURL=Chip.js.map