function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import * as React from 'react';
import { Animated, Platform, StyleSheet, View } from 'react-native';
import color from 'color';
import Surface from '../Surface';
import Text from '../Typography/Text';
import TouchableRipple from '../TouchableRipple/TouchableRipple.native';
import { withTheme } from '../../core/theming';
import { colors as Colors } from '../../styles/tokens';
const Chip = _ref => {
  let {
    mode = 'flat',
    children,
    selected = false,
    disabled = false,
    accessibilityLabel,
    textStyle,
    style,
    theme,
    testID,
    selectedColor,
    ellipsizeMode,
    color: chipColor,
    ...rest
  } = _ref;
  const {
    current: elevation
  } = React.useRef(new Animated.Value(0));
  const {
    dark,
    colors
  } = theme;
  const defaultBackgroundColor = mode === 'outlined' ? 'transparent' : dark ? '#383838' : theme.colors.primary.default;
  const {
    backgroundColor = defaultBackgroundColor,
    borderRadius = 8
  } = StyleSheet.flatten(style) || {};
  const borderColor = mode === 'outlined' ? chipColor ? chipColor : theme.colors.primary.default : backgroundColor;
  const textColor = disabled ? colors.disabled : mode === 'outlined' ? chipColor || theme.colors.primary.default : Colors.white;
  const backgroundColorString = typeof backgroundColor === 'string' ? backgroundColor : defaultBackgroundColor;
  const selectedBackgroundColor = (dark ? color(backgroundColorString).lighten(mode === 'outlined' ? 0.2 : 0.4) : color(backgroundColorString).darken(mode === 'outlined' ? 0.08 : 0.2)).rgb().string();
  const underlayColor = selectedColor ? color(selectedColor).fade(0.5).rgb().string() : selectedBackgroundColor;
  const accessibilityTraits = ['button'];
  const accessibilityState = {
    selected,
    disabled
  };
  if (selected) {
    accessibilityTraits.push('selected');
  }
  if (disabled) {
    accessibilityTraits.push('disabled');
  }
  return /*#__PURE__*/React.createElement(Surface, _extends({
    style: [styles.container, {
      elevation: Platform.OS === 'android' ? elevation : 0,
      backgroundColor: selected ? selectedBackgroundColor : backgroundColor,
      borderColor,
      borderRadius
    }, style]
  }, rest), /*#__PURE__*/React.createElement(TouchableRipple, {
    borderless: true,
    delayPressIn: 0,
    style: [{
      borderRadius
    }, styles.touchable],
    underlayColor: underlayColor,
    disabled: disabled,
    accessibilityLabel: accessibilityLabel
    // @ts-expect-error We keep old a11y props for backwards compat with old RN versions
    ,
    accessibilityTraits: accessibilityTraits,
    accessibilityComponentType: "button",
    accessibilityRole: "button",
    accessibilityState: accessibilityState,
    testID: testID
  }, /*#__PURE__*/React.createElement(View, {
    style: [styles.content]
  }, /*#__PURE__*/React.createElement(Text, {
    selectable: false,
    numberOfLines: 1,
    style: [styles.text, {
      ...theme.fonts.bold,
      color: textColor
      // marginRight: 8,
      // marginLeft: selected ? 4 : 8,
    }, textStyle],
    ellipsizeMode: ellipsizeMode
  }, children))));
};
const styles = StyleSheet.create({
  container: {
    borderWidth: StyleSheet.hairlineWidth * 2,
    borderStyle: 'solid',
    flexDirection: 'column'
  },
  content: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingHorizontal: 10,
    position: 'relative'
  },
  text: {
    // minHeight: 24,
    // lineHeight: 24,
    textAlignVertical: 'center',
    marginVertical: 4,
    // textTransform: 'uppercase',
    fontSize: 12
  },
  touchable: {}
});
export default withTheme(Chip);
//# sourceMappingURL=Chip.js.map