import React from 'react';
import {Image, StyleSheet, View} from 'react-native';
import {IMAGE_WIDTH, COVER_HEIGHT, IMAGE_HEIGHT} from '../../constants';
import {useSelector} from 'react-redux';
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 = ''} = userXId
    ? useSelector((state: RootState) => state.userX[screenType][userXId])
    : useSelector((state: RootState) => state.user);

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

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