import React from 'react';
import {Image, StyleSheet} from 'react-native';
import {useSelector} from 'react-redux';
import {RootState} from '../../store/rootreducer';
import {ScreenType} from '../../types';

const PROFILE_DIM = 100;

interface AvatarProps {
  style?: object;
  userXId: string | undefined;
  screenType: ScreenType;
}
const Avatar: React.FC<AvatarProps> = ({style, screenType, userXId}) => {
  const {avatar} = userXId
    ? useSelector((state: RootState) => state.userX[screenType][userXId])
    : useSelector((state: RootState) => state.user);

  return (
    <Image
      style={[styles.image, style]}
      source={
        avatar
          ? {uri: avatar}
          : require('../../assets/images/avatar-placeholder.png')
      }
    />
  );
};

const styles = StyleSheet.create({
  image: {
    height: PROFILE_DIM,
    width: PROFILE_DIM,
    borderRadius: PROFILE_DIM / 2,
  },
});

export default Avatar;
