import React, {useState} from 'react';
import {Image, ImageStyle, StyleSheet, TouchableOpacity} from 'react-native';
import {normalize} from '../../utils';

interface LikeButtonProps {
  onPress: () => void;
  style: ImageStyle;
  initialLikeState: boolean;
}
const LikeButton: React.FC<LikeButtonProps> = ({
  onPress,
  style,
  initialLikeState,
}) => {
  const [filled, setFilled] = useState(initialLikeState);
  const uri = filled
    ? require('../../assets/images/heart-filled.png')
    : require('../../assets/images/heart-outlined.png');
  return (
    <TouchableOpacity
      onPress={() => {
        if (filled === initialLikeState) {
          setFilled(!filled);
          onPress();
        }
      }}>
      <Image style={[styles.image, style]} source={uri} />
    </TouchableOpacity>
  );
};

const styles = StyleSheet.create({
  image: {
    width: normalize(18),
    height: normalize(15),
  },
});

export default LikeButton;
