import React, { useRef, useEffect } from 'react';
import {
    Animated,
    StyleSheet,
    View,
    Image,
    Dimensions,
    ImageSourcePropType
} from 'react-native';
import {
    widthPercentageToDP as wp,
    heightPercentageToDP as hp
} from 'react-native-responsive-screen';

interface SlideInImageProps {
    source: ImageSourcePropType;
}

const SlideInImage: React.FC<SlideInImageProps> = ({ source }) => {
    const slideAnim = useRef(new Animated.Value(-200)).current;
    useEffect(() => {
        Animated.timing(slideAnim, {
            toValue: 0,
            duration: 1000,
            useNativeDriver: true
        }).start();
    }, [slideAnim]);

    return (
        <Animated.View
            style={[
                styles.imageContainer,
                {
                    transform: [{ translateX: slideAnim }]
                }
            ]}
        >
            <Image source={source} style={styles.image} resizeMode="contain" />
        </Animated.View>
    );
};

const styles = StyleSheet.create({
    imageContainer: {
        flex: 1
    },
    image: {
        height: wp('40%'),
        width: wp('100%')
    }
});

export default SlideInImage;
