"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = require("react");
var _reactNative = require("react-native");
var _reactNativeImagePicker = require("react-native-image-picker");
const useImagePicker = options => {
  const [imageUri, setImageUri] = (0, _react.useState)(null);
  const imageUriRef = (0, _react.useRef)(null);
  const openImageGallery = async () => {
    await (0, _reactNativeImagePicker.launchImageLibrary)(options, response => {
      if (response.didCancel) {
        console.log('User cancelled image picker');
      } else if (response.errorCode) {
        _reactNative.Alert.alert('ImagePicker Error:', response.errorCode + ', ' + response.errorMessage);
      } else {
        if (response.assets) {
          imageUriRef.current = response.assets[0].uri;
          setImageUri(response.assets[0].uri);
        }
      }
    });
  };
  const openCamera = async () => {
    await (0, _reactNativeImagePicker.launchCamera)(options, response => {
      if (response.didCancel) {
        console.log('User cancelled image picker');
      } else if (response.errorCode) {
        _reactNative.Alert.alert('ImagePicker Error:', response.errorCode + ', ' + response.errorMessage);
      } else {
        if (response.assets) {
          imageUriRef.current = response.assets[0].uri;
          setImageUri(response.assets[0].uri);
        }
      }
    });
  };
  const removeSelectedImage = () => {
    setImageUri(null);
  };
  return {
    imageUri,
    removeSelectedImage,
    openImageGallery,
    openCamera
  };
};
var _default = exports.default = useImagePicker;
//# sourceMappingURL=useImagePicker.js.map