"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Chip = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _useTheme = require("../theme/use-theme.js");
var _usePressAnimation = require("../hooks/usePressAnimation.js");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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 = (0, _useTheme.useTheme)();
  const {
    scaleAnim,
    onPressIn,
    onPressOut
  } = (0, _usePressAnimation.usePressAnimation)(PRESS_SCALE);
  const colors = useChipColors(color, variant, selected, theme);
  const sizeConfig = SIZE_CONFIG[size];
  const containerStyle = (0, _react.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 = (0, _react.useMemo)(() => ({
    fontSize: sizeConfig.fontSize,
    fontWeight: '500',
    color: colors.fg
  }), [sizeConfig, colors]);
  const closeButton = onClose ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
    onPress: onClose,
    hitSlop: {
      top: 6,
      bottom: 6,
      left: 6,
      right: 6
    },
    accessibilityLabel: "Remove",
    accessibilityRole: "button",
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
      style: {
        fontSize: sizeConfig.iconSize,
        color: colors.fg,
        lineHeight: sizeConfig.iconSize
      },
      children: '\u00D7'
    })
  }) : null;
  const content = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: [startIcon, typeof children === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
      style: [labelStyle, textStyle],
      children: children
    }) : children, endIcon, closeButton]
  });
  if (onPress) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
      style: {
        transform: [{
          scale: scaleAnim
        }]
      },
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.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__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
    style: [containerStyle, disabled && {
      opacity: 0.5
    }, style],
    accessibilityLabel: accessibilityLabel,
    testID: testID,
    children: content
  });
};
const Chip = exports.Chip = /*#__PURE__*/(0, _react.memo)(ChipComponent);
Chip.displayName = 'Chip';
//# sourceMappingURL=Chip.js.map