import { TouchableOpacity, View } from 'react-native';
import { useStyles } from './styles';
import { SvgXml } from 'react-native-svg';
import { camera } from '../../../../../../core/assets/icons';
import { getFileUrlWithSize } from '../../../../../utils';
import { Avatar } from '../../../../../components';
import useImagePicker from '../../../../../hooks/useImagePicker';
import { CircularProgressIndicator } from '../../../../../components/CircularProgressIndicator';
export function ImageUpload({
  user,
  value,
  onChange
}) {
  var _user$avatar;
  const {
    styles,
    theme
  } = useStyles();
  const {
    openImageGallery,
    progress
  } = useImagePicker();
  return /*#__PURE__*/React.createElement(View, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(TouchableOpacity, {
    hitSlop: 0.8,
    activeOpacity: 0.7,
    style: styles.imageContainer,
    disabled: progress > 0,
    onPress: () => {
      openImageGallery({
        mediaType: 'photo',
        selectionLimit: 1,
        includeBase64: false,
        quality: 1
      }).then(file => {
        if (file) {
          onChange(file);
        }
      });
    }
  }, /*#__PURE__*/React.createElement(Avatar.User, {
    viewable: false,
    roles: user === null || user === void 0 ? void 0 : user.roles,
    imageStyle: styles.image,
    userId: (user === null || user === void 0 ? void 0 : user.userId) || '',
    shouldRedirectToUserProfile: false,
    uri: getFileUrlWithSize((value === null || value === void 0 ? void 0 : value.fileUrl) || (user === null || user === void 0 || (_user$avatar = user.avatar) === null || _user$avatar === void 0 ? void 0 : _user$avatar.fileUrl))
  }), /*#__PURE__*/React.createElement(View, {
    style: styles.iconContainer
  }, progress > 0 ? /*#__PURE__*/React.createElement(CircularProgressIndicator, {
    size: 24,
    strokeWidth: 2.3,
    progress: progress,
    progressColor: theme.colors.white,
    backgroundColor: theme.colors.white
  }) : /*#__PURE__*/React.createElement(SvgXml, {
    width: 24,
    height: 24,
    xml: camera(),
    color: theme.colors.white
  }))));
}
//# sourceMappingURL=ImageUpload.js.map