"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _color = _interopRequireDefault(require("color"));
var _Surface = _interopRequireDefault(require("../Surface"));
var _Text = _interopRequireDefault(require("../Typography/Text"));
var _TouchableRipple = _interopRequireDefault(require("../TouchableRipple/TouchableRipple.native"));
var _theming = require("../../core/theming");
var _tokens = require("../../styles/tokens");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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); }
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 _reactNative.Animated.Value(0));
  const {
    dark,
    colors
  } = theme;
  const defaultBackgroundColor = mode === 'outlined' ? 'transparent' : dark ? '#383838' : theme.colors.primary.default;
  const {
    backgroundColor = defaultBackgroundColor,
    borderRadius = 8
  } = _reactNative.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 : _tokens.colors.white;
  const backgroundColorString = typeof backgroundColor === 'string' ? backgroundColor : defaultBackgroundColor;
  const selectedBackgroundColor = (dark ? (0, _color.default)(backgroundColorString).lighten(mode === 'outlined' ? 0.2 : 0.4) : (0, _color.default)(backgroundColorString).darken(mode === 'outlined' ? 0.08 : 0.2)).rgb().string();
  const underlayColor = selectedColor ? (0, _color.default)(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.default, _extends({
    style: [styles.container, {
      elevation: _reactNative.Platform.OS === 'android' ? elevation : 0,
      backgroundColor: selected ? selectedBackgroundColor : backgroundColor,
      borderColor,
      borderRadius
    }, style]
  }, rest), /*#__PURE__*/React.createElement(_TouchableRipple.default, {
    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(_reactNative.View, {
    style: [styles.content]
  }, /*#__PURE__*/React.createElement(_Text.default, {
    selectable: false,
    numberOfLines: 1,
    style: [styles.text, {
      ...theme.fonts.bold,
      color: textColor
      // marginRight: 8,
      // marginLeft: selected ? 4 : 8,
    }, textStyle],
    ellipsizeMode: ellipsizeMode
  }, children))));
};
const styles = _reactNative.StyleSheet.create({
  container: {
    borderWidth: _reactNative.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: {}
});
var _default = (0, _theming.withTheme)(Chip);
exports.default = _default;
//# sourceMappingURL=Chip.js.map