"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ImageUpload = ImageUpload;
var _reactNative = require("react-native");
var _styles = require("./styles");
var _reactNativeSvg = require("react-native-svg");
var _icons = require("../../../../../../core/assets/icons");
var _utils = require("../../../../../utils");
var _components = require("../../../../../components");
var _useImagePicker = _interopRequireDefault(require("../../../../../hooks/useImagePicker"));
var _CircularProgressIndicator = require("../../../../../components/CircularProgressIndicator");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function ImageUpload({
  user,
  value,
  onChange
}) {
  var _user$avatar;
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const {
    openImageGallery,
    progress
  } = (0, _useImagePicker.default)();
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container
  }, /*#__PURE__*/React.createElement(_reactNative.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(_components.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: (0, _utils.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(_reactNative.View, {
    style: styles.iconContainer
  }, progress > 0 ? /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 24,
    strokeWidth: 2.3,
    progress: progress,
    progressColor: theme.colors.white,
    backgroundColor: theme.colors.white
  }) : /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: 24,
    height: 24,
    xml: (0, _icons.camera)(),
    color: theme.colors.white
  }))));
}
//# sourceMappingURL=ImageUpload.js.map