import React from 'react';
import { Avatar } from 'react-native-elements';

import { isEmpty } from '../../utils/aux';

const TagferAvatar = ({ size, photoURL }) => {
  const uri = !isEmpty(photoURL) ? { uri: photoURL } : null;
  const icon = isEmpty(photoURL) ? { name: 'user', type: 'entypo' } : null;

  return (
    <Avatar
      {...getSize(size)}
      rounded
      icon={icon}
      source={uri}
      activeOpacity={0.7}
    />
  );
};

function getSize(size) {
  switch (size) {
    case 'small': return { small: true };
    case 'medium': return { medium: true };
    case 'large': return { large: true };
    case 'xlarge': return { xlarge: true };
    default: throw new Error('Unsupported Tagfer Avatar size');
  }
}
export default TagferAvatar;
