<commit_before>import React from 'react';
import ReactDOM from 'react-dom';
import _ from 'underscore';
import $ from 'jquery';

import StatusPopOver from './StatusPopOver.jsx';
import {validateDeck} from './deck-validator';

class DeckSummary extends React.Component {
    constructor() {
        super();

        this.onCardMouseOut = this.onCardMouseOut.bind(this);
        this.onCardMouseOver = this.onCardMouseOver.bind(this);

        this.state = {
            status: '',
            cardToShow: '',
            provinceCount: 0,
            drawCount: 0,
            conflictDrawCount: 0,
            dynastyDrawCount: 0
        };
    }

    componentWillMount() {
        this.updateDeck(validateDeck(this.props));
    }

    componentWillReceiveProps(newProps) {
        this.updateDeck(validateDeck(newProps));
    }

    updateStatus() {
        if(this.state.status === 'Valid') {
            if($(this.refs.popover).popover) {
                $(this.refs.popover).popover('disable');
            }

            return;
        }

        var popoverContent = $($.parseHTML(ReactDOM.findDOMNode(this.refs.popoverContent).outerHTML)).removeClass('hidden').html();
        // XXX Neccessary until I figure out how to make this work for tests
        if($(this.refs.popover).popover) {
            $(this.refs.popover).popover({ trigger: 'hover', html: true });
            $(this.refs.popover).data('bs.popover').options.content = popoverContent;
        }
    }

    updateDeck(status) {
        this.setState({ status: status.status, conflictDrawCount: status.conflictDrawCount, dynastyDrawCount: status.dynastyDrawCount, provinceCount: status.provinceCount, extendedStatus: status.extendedStatus }, this.updateStatus);
    }

    onCardMouseOver(event) {
        var cardToDisplay = _.filter(this.props.cards, card => {
            return event.target.innerText === card.label;
        });

        this.setState({ cardToShow: cardToDisplay[0] });
    }

    onCardMouseOut() {
        this.setState({ cardToShow: undefined });
    }

    getCardsToRender() {
        var cardsToRender = [];
        var groupedCards = {};
        var combinedCards = _.union(this.props.provinceCards, this.props.stronghold, this.props.conflictDrawCards, this.props.dynastyDrawCards);

        _.each(combinedCards, (card) => {
            if(!groupedCards[card.card.type]) {
                groupedCards[card.card.type] = [card];
            } else {
                groupedCards[card.card.type].push(card);
            }
        });

        _.each(groupedCards, (cardList, key) => {
            var cards = [];
            var count = 0;

            _.each(cardList, card => {
                cards.push(<div key={ card.card.code }><span>{card.count + 'x '}</span><span className='card-link' onMouseOver={ this.onCardMouseOver } onMouseOut={ this.onCardMouseOut }>{ card.card.name }</span></div>);
                count += parseInt(card.count);<commit_msg>Fix image display<commit_after>import React from 'react';
import ReactDOM from 'react-dom';
import _ from 'underscore';
import $ from 'jquery';

import StatusPopOver from './StatusPopOver.jsx';
import {validateDeck} from './deck-validator';

class DeckSummary extends React.Component {
    constructor() {
        super();

        this.onCardMouseOut = this.onCardMouseOut.bind(this);
        this.onCardMouseOver = this.onCardMouseOver.bind(this);

        this.state = {
            status: '',
            cardToShow: '',
            provinceCount: 0,
            drawCount: 0,
            conflictDrawCount: 0,
            dynastyDrawCount: 0
        };
    }

    componentWillMount() {
        this.updateDeck(validateDeck(this.props));
    }

    componentWillReceiveProps(newProps) {
        this.updateDeck(validateDeck(newProps));
    }

    updateStatus() {
        if(this.state.status === 'Valid') {
            if($(this.refs.popover).popover) {
                $(this.refs.popover).popover('disable');
            }

            return;
        }

        var popoverContent = $($.parseHTML(ReactDOM.findDOMNode(this.refs.popoverContent).outerHTML)).removeClass('hidden').html();
        // XXX Neccessary until I figure out how to make this work for tests
        if($(this.refs.popover).popover) {
            $(this.refs.popover).popover({ trigger: 'hover', html: true });
            $(this.refs.popover).data('bs.popover').options.content = popoverContent;
        }
    }

    updateDeck(status) {
        this.setState({ status: status.status, conflictDrawCount: status.conflictDrawCount, dynastyDrawCount: status.dynastyDrawCount, provinceCount: status.provinceCount, extendedStatus: status.extendedStatus }, this.updateStatus);
    }

    onCardMouseOver(event) {
        var cardToDisplay = _.filter(this.props.cards, card => {
            return event.target.innerText === card.name;
        });

        this.setState({ cardToShow: cardToDisplay[0] });
    }

    onCardMouseOut() {
        this.setState({ cardToShow: undefined });
    }

    getCardsToRender() {
        var cardsToRender = [];
        var groupedCards = {};
        var combinedCards = _.union(this.props.provinceCards, this.props.stronghold, this.props.conflictDrawCards, this.props.dynastyDrawCards);

        _.each(combinedCards, (card) => {
            if(!groupedCards[card.card.type]) {
                groupedCards[card.card.type] = [card];
            } else {
                groupedCards[card.card.type].push(card);
            }
        });

        _.each(groupedCards, (cardList, key) => {
            var cards = [];
            var count = 0;

            _.each(cardList, card => {
                cards.push(<div key={ card.card.code }><span>{card.count + 'x '}</span><span className='card-link' onMouseOver={ this.onCardMouseOver } onMouseOut={ this.onCardMouseOut }>{ card.card.name }</span></div>);
                count += parseInt(card.count);
{'fraction_non_alphanumeric': 0.13670886075949368, 'fraction_numerical': 0.0020253164556962027, 'mean_word_length': 2.384351798972016, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7423361', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1714, 'n_words': 297}