{"size": 1662, "ext": "js", "max_stars_repo_path": "src/client/components/deck/deck.js", "max_stars_repo_name": "TNG/elevation-of-privilege", "max_stars_repo_stars_event_min_datetime": "2021-09-24T12:07:36.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-29T13:09:28.000Z", "max_issues_repo_path": "src/client/components/deck/deck.js", "max_issues_repo_name": "TNG/elevation-of-privilege", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/client/components/deck/deck.js", "max_forks_repo_name": "TNG/elevation-of-privilege", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 10, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.8059701493, "max_line_length": 73, "alphanum_fraction": 0.6010830325}
import React from 'react';
import PropTypes from 'prop-types';
import { getValidMoves } from '../../../utils/utils';
import { isGameModeCornucopia } from '../../../utils/constants';

class Deck extends React.Component {
  static get propTypes() {
    return {
      suit: PropTypes.any.isRequired,
      cards: PropTypes.any.isRequired,
      isInThreatStage: PropTypes.bool,
      round: PropTypes.any.isRequired,
      current: PropTypes.bool.isRequired,
      active: PropTypes.bool.isRequired,
      onCardSelect: PropTypes.func.isRequired,
      startingCard: PropTypes.string.isRequired,
      gameMode: PropTypes.string.isRequired,
    };
  }

  static get defaultProps() {
    return {
      isInThreatStage: false,
    };
  }

  getRenderedDeck() {
    let left = this.props.cards;
    let suit = this.props.suit;
    let validMoves = [];

    if (
      this.props.current &&
      this.props.active &&
      !this.props.isInThreatStage
    ) {
      validMoves = getValidMoves(
        left,
        suit,
        this.props.round,
        this.props.startingCard,
      );
    }

    let deck = left.map((e) => (
      <li
        key={e}
        className={` playing-card ${
          isGameModeCornucopia(this.props.gameMode)
            ? `cornucopiacard ccard${e.toLowerCase()}`
            : `card${e.toLowerCase()}`
        } ${validMoves.includes(e) ? 'active' : ''} card-rounded scaled`}
        onClick={() => this.props.onCardSelect(e)}
      />
    ));

    return <ul className="hand">{deck}</ul>;
  }

  render() {
    let deck = this.getRenderedDeck();
    return <div className="playingCards">{deck}</div>;
  }
}

export default Deck;
