<commit_before>import React from 'react';
import _ from 'underscore';

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

        this.onMouseOver = this.onMouseOver.bind(this);
        this.onMouseOut = this.onMouseOut.bind(this);

        this.state = {
            showMenu: false
        };
    }

    onMouseOver(card) {
        if(this.props.onMouseOver) {
            this.props.onMouseOver(card);
        }
    }

    onMouseOut() {
        if(this.props.onMouseOut) {
            this.props.onMouseOut();
        }
    }

    onCardDragStart(event, card, source) {
        var dragData = { card: card, source: source };

        event.dataTransfer.setData('Text', JSON.stringify(dragData));
    }

    onClick(event, card, source) {
        event.preventDefault();
        event.stopPropagation();

        if(!_.isEmpty(this.props.card.menu)) {
            this.setState({showMenu: !this.state.showMenu});

            return;
        }

        if(this.props.onClick) {
            this.props.onClick(source, card);
        }
    }

    onMenuItemClick(menuItem) {
        if(this.props.onMenuItemClick) {
            this.props.onMenuItemClick(this.props.source, this.props.card, menuItem);
        }
    }

    getCounters() {
        var counters = {};

        if(this.props.source !== 'play area') {
            return null;
        }

        counters['power'] = this.props.card.power;
        counters['strength'] = this.props.card.baseStrength !== this.props.card.strength ? this.props.card.strength : 0;
        counters['dupe'] = this.props.card.dupes && this.props.card.dupes.length > 0 ? this.props.card.dupes.length : 0;

        _.extend(counters, this.props.card.tokens);

        var filteredCounters = _.omit(counters, counter => {
            return _.isUndefined(counter) || _.isNull(counter) || counter <= 0;
        });

        var counterDivs = _.map(filteredCounters, (counterValue, key) => {
            return <div key={key} className={'counter ' + key}>{counterValue}</div>;
        });

        return counterDivs.length !== 0 ? (
            <div className='counters ignore-mouse-events'>
                {counterDivs}
            </div>) : null;
    }

    getAttachments() {
        if(this.props.source !== 'play area') {
            return null;
        }

        var offset = 10;
        var attachments = _.map(this.props.card.attachments, attachment => {
            var style = { top: offset + 'px', zIndex: -offset };

            var returnedAttachment = (<Card key={attachment.uuid} style={style} source={this.props.source} card={attachment}
                            onMouseOver={this.props.disableMouseOver ? null : this.onMouseOver.bind(this, attachment)}
                            onMouseOut={this.props.disableMouseOver ? null : this.onMouseOut}
                            onClick={this.props.onClick}
                            onDragStart={ev => this.onCardDragStart(ev, attachment, this.props.source)} />);

            offset += 10;

            return returnedAttachment;
        });

        return attachments;
    }

    getDupes() {
        if(this.props.source !== 'play area') {
            return null;
        }

        var facedownDupes = _.filter(this.props.card.dupes, card => {
            return card.facedown;
        });

        if(!facedownDupes || facedownDupes.length === 0) {
            return;
        }

        var offset = -10;
        var dupes = _.map(facedownDupes, dupe => {
            var style = { 
                top: offset + 'px',
                left: '0px',
                zIndex: offset,
                position: 'absolute' };

            var returnedDupe = (<Card key={dupe.uuid} style={style} source={this.props.source} card={dupe}
                            onMouseOver={this.props.disableMouseOver ? null : this.onMouseOver.bind(this, dupe)}
                            onMouseOut={this.props.disableMouseOver ? null : this.onMouseOut} />);

            offset -= 10;

            return returnedDupe;
        });

        return dupes;
    }

    getMenu() {
        if(this.props.source !== 'play area') {
            return null;
        }

        var menuIndex = 0;
        var menuItems = this.props.card.menu && this.state.showMenu ? _.map(this.props.card.menu, menuItem => {
            return <div key={menuIndex++} onClick={this.onMenuItemClick.bind(this, menuItem)}>{menuItem.text}</div>;
        }) : null;

        return menuItems && menuItems.length !== 0 ? (
            <div className='panel menu'>
                {menuItems}
            </div>
        ) : null;  
    }

    isFacedown() {
        return this.props.card.facedown || !this.props.card.code;
    }

    render() {
        var cardClass = '';
        var imageClass = '';
        var wrapperClass = 'card-wrapper';
        
        if(this.props.card.kneeled || this.props.horizontal) {<commit_msg>agendas are ok<commit_after>import React from 'react';
import _ from 'underscore';

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

        this.onMouseOver = this.onMouseOver.bind(this);
        this.onMouseOut = this.onMouseOut.bind(this);

        this.state = {
            showMenu: false
        };
    }

    onMouseOver(card) {
        if(this.props.onMouseOver) {
            this.props.onMouseOver(card);
        }
    }

    onMouseOut() {
        if(this.props.onMouseOut) {
            this.props.onMouseOut();
        }
    }

    onCardDragStart(event, card, source) {
        var dragData = { card: card, source: source };

        event.dataTransfer.setData('Text', JSON.stringify(dragData));
    }

    onClick(event, card, source) {
        event.preventDefault();
        event.stopPropagation();

        if(!_.isEmpty(this.props.card.menu)) {
            this.setState({showMenu: !this.state.showMenu});

            return;
        }

        if(this.props.onClick) {
            this.props.onClick(source, card);
        }
    }

    onMenuItemClick(menuItem) {
        if(this.props.onMenuItemClick) {
            this.props.onMenuItemClick(this.props.source, this.props.card, menuItem);
        }
    }

    getCounters() {
        var counters = {};

        if(this.props.source !== 'play area') {
            return null;
        }

        counters['power'] = this.props.card.power;
        counters['strength'] = this.props.card.baseStrength !== this.props.card.strength ? this.props.card.strength : 0;
        counters['dupe'] = this.props.card.dupes && this.props.card.dupes.length > 0 ? this.props.card.dupes.length : 0;

        _.extend(counters, this.props.card.tokens);

        var filteredCounters = _.omit(counters, counter => {
            return _.isUndefined(counter) || _.isNull(counter) || counter <= 0;
        });

        var counterDivs = _.map(filteredCounters, (counterValue, key) => {
            return <div key={key} className={'counter ' + key}>{counterValue}</div>;
        });

        return counterDivs.length !== 0 ? (
            <div className='counters ignore-mouse-events'>
                {counterDivs}
            </div>) : null;
    }

    getAttachments() {
        if(this.props.source !== 'play area') {
            return null;
        }

        var offset = 10;
        var attachments = _.map(this.props.card.attachments, attachment => {
            var style = { top: offset + 'px', zIndex: -offset };

            var returnedAttachment = (<Card key={attachment.uuid} style={style} source={this.props.source} card={attachment}
                            onMouseOver={this.props.disableMouseOver ? null : this.onMouseOver.bind(this, attachment)}
                            onMouseOut={this.props.disableMouseOver ? null : this.onMouseOut}
                            onClick={this.props.onClick}
                            onDragStart={ev => this.onCardDragStart(ev, attachment, this.props.source)} />);

            offset += 10;

            return returnedAttachment;
        });

        return attachments;
    }

    getDupes() {
        if(this.props.source !== 'play area') {
            return null;
        }

        var facedownDupes = _.filter(this.props.card.dupes, card => {
            return card.facedown;
        });

        if(!facedownDupes || facedownDupes.length === 0) {
            return;
        }

        var offset = -10;
        var dupes = _.map(facedownDupes, dupe => {
            var style = { 
                top: offset + 'px',
                left: '0px',
                zIndex: offset,
                position: 'absolute' };

            var returnedDupe = (<Card key={dupe.uuid} style={style} source={this.props.source} card={dupe}
                            onMouseOver={this.props.disableMouseOver ? null : this.onMouseOver.bind(this, dupe)}
                            onMouseOut={this.props.disableMouseOver ? null : this.onMouseOut} />);

            offset -= 10;

            return returnedDupe;
        });

        return dupes;
    }

    getMenu() {
        if(this.props.source !== 'play area' && this.props.source !== 'agenda') {
            return null;
        }

        var menuIndex = 0;
        var menuItems = this.props.card.menu && this.state.showMenu ? _.map(this.props.card.menu, menuItem => {
            return <div key={menuIndex++} onClick={this.onMenuItemClick.bind(this, menuItem)}>{menuItem.text}</div>;
        }) : null;

        return menuItems && menuItems.length !== 0 ? (
            <div className='panel menu'>
                {menuItems}
            </div>
        ) : null;  
    }

    isFacedown() {
        return this.props.card.facedown || !this.props.card.code;
    }

    render() {
        var cardClass = '';
        var imageClass = '';
        var wrapperClass = 'card-wrapper';
        
        if(this.props.card.kneeled || this.props.horizontal) {
{'fraction_non_alphanumeric': 0.13539240506329114, 'fraction_numerical': 0.0034430379746835443, 'mean_word_length': 1.7969413763806288, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 39, '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': '4528729', 'n_tokens_mistral': 2934, 'n_tokens_neox': 2806, 'n_words': 502}