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

interface CoverProps {
  userXId: string | undefined;
  screenType: ScreenType;
}
const Cover: React.FC<CoverProps> = ({userXId, screenType}) => {
  const {cover} = useSelector((state: RootState) =>
    userXId ? state.userX[screenType][userXId] : state.user,
  );

  return (
    <View style={[styles.container]}>
      <Image
        style={styles.image}
        defaultSource={require('../../assets/images/cover-placeholder.png')}
        source={{uri: cover, cache: 'reload'}}
      />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    position: 'absolute',
  },
  image: {
    width: IMAGE_WIDTH,
    height: COVER_HEIGHT,
  },
});
export default Cover;
