import PropTypes from 'prop-types';
import React, { PureComponent } from 'react';
import styles from './ImdbRating.css';

class ImdbRating extends PureComponent {

  //
  // Render

  render() {

    const {
      ratings,
      hideIcon,
      iconSize
    } = this.props;

    const imdbImage = 'data:image/svg+xml;base64,[encoded data, 5344 characters]';

    const rating = ratings.imdb;

    let ratingString = '0.0';

    if (rating) {
      ratingString = `${rating.value}`;
    }

    return (
      <span title={`${rating.votes} votes`}>
        {
          !hideIcon &&
            <img
              className={styles.image}
              src={imdbImage}
              style={{
                height: `${iconSize}px`
              }}
            />
        }

        {ratingString}
      </span>
    );
  }
}

ImdbRating.propTypes = {
  ratings: PropTypes.object.isRequired,
  iconSize: PropTypes.number.isRequired,
  hideIcon: PropTypes.bool
};

ImdbRating.defaultProps = {
  iconSize: 14
};

export default ImdbRating;
