import {useNavigation} from '@react-navigation/native';
import React from 'react';
import {Image, Text, TouchableOpacity} from 'react-native';
import {ScreenType} from '../../types';
import {navigateToImagePicker} from '../../utils/camera';
import {styles} from './styles';

interface GalleryIconProps {
  screenType: ScreenType;
  title: string;
  mostRecentPhoto: string;
}

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

export default GalleryIcon;
