"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _polished = require("polished");
var _enums = require("../../../../../enums");
var _styles = require("./styles");
var _reactNativeSvg = require("react-native-svg");
var _elements = require("../../../../../elements");
var _utils = require("../../../../../utils");
var _icons = require("../../../../../../core/assets/icons");
var _CameraButton = _interopRequireDefault(require("../../../../../elements/CameraButton"));
var _reactNativeLinearGradient = _interopRequireDefault(require("react-native-linear-gradient"));
var _bottomSheetSlice = require("../../../../../../core/stores/slices/bottomSheetSlice");
var _reactNative = require("react-native");
var _CircularProgressIndicator = require("../../../../../components/CircularProgressIndicator");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function CoverImageUpload({
  value,
  progress,
  onChange,
  openCamera,
  openImageGallery
}) {
  const {
    styles,
    theme
  } = (0, _styles.useStyles)();
  const {
    openBottomSheet,
    closeBottomSheet
  } = (0, _bottomSheetSlice.useBottomSheet)();
  const onImageFromCamera = async () => {
    closeBottomSheet();
    const file = await openCamera({
      mediaType: 'photo',
      quality: 1,
      includeExtra: true,
      saveToPhotos: false,
      presentationStyle: 'overFullScreen'
    });
    onChange(file || null);
  };
  const onImageUpload = async () => {
    closeBottomSheet();
    const file = await openImageGallery({
      quality: 1,
      mediaType: 'photo',
      selectionLimit: 1,
      includeExtra: true
    });
    onChange(file || null);
  };
  return /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.container
  }, value ? /*#__PURE__*/React.createElement(_reactNative.Image, {
    style: styles.uploadedImage,
    source: {
      uri: (0, _utils.getFileUrlWithSize)(value.fileUrl)
    }
  }) : /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.defaultImage
  }), /*#__PURE__*/React.createElement(_reactNativeLinearGradient.default, {
    locations: [1, 1],
    style: styles.imageOverlay,
    colors: value ? ['rgba(0,0,0,0.5)', 'rgba(0,0,0,0.5)'] : ['rgba(0,0,0,0.5)', theme.colors.primaryShade3]
  }), progress > 0 ? /*#__PURE__*/React.createElement(_reactNative.View, {
    style: styles.button
  }, /*#__PURE__*/React.createElement(_CircularProgressIndicator.CircularProgressIndicator, {
    size: 24,
    strokeWidth: 2.3,
    progress: progress,
    progressColor: theme.colors.primary,
    backgroundColor: theme.colors.background
  })) : /*#__PURE__*/React.createElement(_reactNative.TouchableOpacity, {
    style: styles.button,
    onPress: () => openBottomSheet({
      content: /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_CameraButton.default, {
        onPress: onImageFromCamera,
        pageId: _enums.PageID.community_setup_page
      }), /*#__PURE__*/React.createElement(_elements.ImageButton, {
        onPress: onImageUpload,
        pageId: _enums.PageID.community_setup_page
      }))
    })
  }, /*#__PURE__*/React.createElement(_reactNativeSvg.SvgXml, {
    width: 32,
    height: 32,
    xml: (0, _icons.imageUpload)(),
    color: (0, _polished.rgba)(theme.colors.background, _reactNative.Platform.OS === 'android' ? 1 : 0.8)
  })));
}
var _default = exports.default = CoverImageUpload;
//# sourceMappingURL=index.js.map