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 color from 'color';
import * as React from 'react';
import { Alert, Linking, Platform, StyleSheet, View } from 'react-native';
import TouchableRipple from '../TouchableRipple/TouchableRipple.native';
import Text from '../Typography/Text';
import { withTheme } from '../../core/theming';
import { colors as Colors } from '../../styles/tokens';
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 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 Linking.openURL(href);
      } else {
        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, {
      rippleColor: "#355DFF",
      onPress: handlePress,
      style: {
        marginRight: 24
      }
    }, /*#__PURE__*/React.createElement(Text, {
      selectable: false,
      numberOfLines: descriptionNumberOfLines,
      ellipsizeMode: descriptionEllipsizeMode,
      style: [styles.description, {
        color: '#355DFF',
        ...theme.fonts.semiBold
      }, descriptionStyle, Platform.OS === 'web' && {
        fontFamily: 'Inter',
        fontWeight: 700
      }]
    }, description)) : /*#__PURE__*/React.createElement(Text, {
      selectable: false,
      numberOfLines: descriptionNumberOfLines,
      ellipsizeMode: descriptionEllipsizeMode,
      style: [styles.description, {
        color: textColor,
        ...theme.fonts.semiBold
      }, descriptionStyle, 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, {
      selectable: false,
      ellipsizeMode: titleEllipsizeMode,
      numberOfLines: titleNumberOfLines,
      style: [styles.label, {
        ...theme.fonts.semiBold
      }, labelStyle, Platform.OS === 'web' && {
        fontFamily: 'Inter'
      }]
    }, label);
  };
  const textColor = color(theme.colors.text).alpha(0.54).rgb().string();
  return /*#__PURE__*/React.createElement(TouchableRipple, _extends({}, rest, {
    style: [styles.container, style],
    onPress: onPress
  }), /*#__PURE__*/React.createElement(View, {
    style: styles.row
  }, /*#__PURE__*/React.createElement(View, {
    style: [styles.item, styles.content]
  }, renderTitle(), itemText ? renderDescription(Colors.black, itemText) : null), right ? right({
    color: textColor,
    style: itemText ? styles.iconMarginRight : {
      ...styles.iconMarginRight,
      ...styles.marginVerticalNone
    }
  }) : null));
};
ListItem.displayName = 'List.Item';
const styles = StyleSheet.create({
  container: {
    borderWidth: 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'
  }
});
export default withTheme(ListItem);
//# sourceMappingURL=ListItem.js.map