import React from 'react';
import {Image, Text, TouchableOpacity, View} from 'react-native';
import {navigateToImagePicker} from '../../utils/camera';
import {Image as ImageType} from 'react-native-image-crop-picker';
import {styles} from './styles';

interface GalleryIconProps {
  mostRecentPhotoUri: string;
  callback: (pic: ImageType) => void;
}

/*
 * Displays the most recent photo in the user's gallery
 * On click, navigates to the image picker
 */
export const GalleryIcon: React.FC<GalleryIconProps> = ({
  mostRecentPhotoUri,
  callback,
}) => {
  return (
    <TouchableOpacity
      onPress={() => navigateToImagePicker(callback)}
      style={styles.saveButton}>
      {mostRecentPhotoUri !== '' ? (
        <Image
          source={{uri: mostRecentPhotoUri}}
          width={40}
          height={40}
          style={styles.galleryIcon}
        />
      ) : (
        <View style={styles.galleryIconEmpty} />
      )}
      <Text style={styles.saveButtonLabel}>Gallery</Text>
    </TouchableOpacity>
  );
};

export default GalleryIcon;
