"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _color = _interopRequireDefault(require("color"));
var React = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _TouchableRipple = _interopRequireDefault(require("../TouchableRipple/TouchableRipple.native"));
var _Text = _interopRequireDefault(require("../Typography/Text"));
var _theming = require("../../core/theming");
var _tokens = require("../../styles/tokens");
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 _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 ListItem = _ref => {
  let {
    right,
    label,
    href,
    text: itemText,
    onPress,
    theme,
    style,
    labelStyle,
    titleNumberOfLines = 1,
    descriptionNumberOfLines = 2,
    titleEllipsizeMode,
    descriptionEllipsizeMode,
    descriptionStyle,
    ...rest
  } = _ref;
  const renderDescription = (textColor, description) => {
    const handlePress = React.useCallback(async () => {
      // Checking if the link is supported for links with custom URL scheme.
      const supported = await _reactNative.Linking.canOpenURL(href);
      if (supported) {
        // Opening the link with some app, if the URL scheme is "http" the web link should be opened
        // by some browser in the mobile
        await _reactNative.Linking.openURL(href);
      } else {
        _reactNative.Alert.alert(`Don't know how to open this URL: ${href}`);
      }
    }, [href]);
    return typeof description === 'function' ? description({
      selectable: false,
      ellipsizeMode: descriptionEllipsizeMode,
      color: textColor,
      fontSize: styles.description.fontSize
    }) : href ? /*#__PURE__*/React.createElement(_TouchableRipple.default, {
      rippleColor: "#355DFF",
      onPress: handlePress,
      style: {
        marginRight: 24
      }
    }, /*#__PURE__*/React.createElement(_Text.default, {
      selectable: false,
      numberOfLines: descriptionNumberOfLines,
      ellipsizeMode: descriptionEllipsizeMode,
      style: [styles.description, {
        color: '#355DFF',
        ...theme.fonts.semiBold
      }, descriptionStyle, _reactNative.Platform.OS === 'web' && {
        fontFamily: 'Inter',
        fontWeight: 700
      }]
    }, description)) : /*#__PURE__*/React.createElement(_Text.default, {
      selectable: false,
      numberOfLines: descriptionNumberOfLines,
      ellipsizeMode: descriptionEllipsizeMode,
      style: [styles.description, {
        color: textColor,
        ...theme.fonts.semiBold
      }, descriptionStyle, _reactNative.Platform.OS === 'web' && {
        fontFamily: 'Inter',
        fontWeight: 700
      }]
    }, description);
  };
  const renderTitle = () => {
    const titleColor = '#CCCDD3';
    return typeof label === 'function' ? label({
      selectable: false,
      ellipsizeMode: titleEllipsizeMode,
      color: titleColor,
      fontSize: styles.label.fontSize
    }) : /*#__PURE__*/React.createElement(_Text.default, {
      selectable: false,
      ellipsizeMode: titleEllipsizeMode,
      numberOfLines: titleNumberOfLines,
      style: [styles.label, {
        ...theme.fonts.semiBold
      }, labelStyle, _reactNative.Platform.OS === 'web' && {
        fontFamily: 'Inter'
      }]
    }, label);
  };
  const textColor = (0, _color.default)(theme.colors.text).alpha(0.54).rgb().string();
  return /*#__PURE__*/React.createElement(_TouchableRipple.default, _extends({}, rest, {
    style: [styles.container, style],
    onPress: onPress
  }), /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.row
  }, /*#__PURE__*/React.createElement(_reactNative.View, {
    style: [styles.item, styles.content]
  }, renderTitle(), itemText ? renderDescription(_tokens.colors.black, itemText) : null), right ? right({
    color: textColor,
    style: itemText ? styles.iconMarginRight : {
      ...styles.iconMarginRight,
      ...styles.marginVerticalNone
    }
  }) : null));
};
ListItem.displayName = 'List.Item';
const styles = _reactNative.StyleSheet.create({
  container: {
    borderWidth: _reactNative.StyleSheet.hairlineWidth * 2,
    width: '100%',
    borderRadius: 16,
    borderColor: '#CCCDD3'
  },
  row: {
    flexDirection: 'row',
    alignItems: 'center',
    paddingRight: 24
  },
  label: {
    fontSize: 10,
    color: '#CCCDD3',
    letterSpacing: 0.9,
    textTransform: 'uppercase'
  },
  description: {
    fontSize: 14
  },
  marginVerticalNone: {
    marginVertical: 0
  },
  iconMarginRight: {
    marginRight: 0
  },
  item: {
    marginVertical: 16,
    paddingLeft: 24
  },
  content: {
    flex: 1,
    justifyContent: 'center'
  }
});
var _default = (0, _theming.withTheme)(ListItem);
exports.default = _default;
//# sourceMappingURL=ListItem.js.map