<commit_before>import React, { Component } from 'react';
import {ref} from '../firebase'
import CardModal from './CardModal'
import { Col, Row, Tooltip, Modal, Button } from 'react-bootstrap';
import {cardArray} from '../cards/cards.js';
import {connect} from 'react-redux'

class CardGrid extends Component {
  constructor(){
    super()
    this.state = {
      showCardInfo: false,
      modalElement: {},
      insufficientFunds: true
    }
    this.disableButton = this.disableButton.bind(this)
  }

  disableButton(element){
  //check if enough money
    /*
     if(this.props.game.turn !== 'playerOne'){
       this.setState({insufficientFunds: true})
     } else{
       this.setState({insufficientFunds: false})
     }
    
     if(this.props.game.phase !== 'buy'){
       this.setState({insufficientFunds: true})
     } else{
       this.setState({insufficientFunds: false})
     }
     */
     if(this.props.game.players[this.props.game.turn].money < element.cost){
        this.setState({insufficientFunds: true})
     } else{
       this.setState({insufficientFunds: false})
     } 
  }

  render() {
    let close = () => this.setState({showCardInfo: false})

    return (

      <div className="game-grid">
        <CardModal
          game={this.props.game}
          close={() => close()}
          show={this.state.showCardInfo}
          insufficientFunds={this.state.insufficientFunds}
          element={this.state.modalElement}
          quantity={this.props.game.cards[this.state.modalElement.refName]}
        />
        {cardArray.map((element, index) => {
          return (
            <Col sm={4} className="col-lg-5ths card-cont modal-container" key={index}
              onClick={(evt) => {
              console.log('ELEMENT', element)
              evt.preventDefault()
              this.setState({
                showCardInfo: true,
                modalElement: element
              })
              this.disableButton(element)<commit_msg>buy logic working as expected now, player can only buy if: its their turn, they are on buy phase and have enough money<commit_after>import React, { Component } from 'react';
import {ref} from '../firebase'
import CardModal from './CardModal'
import { Col, Row, Tooltip, Modal, Button } from 'react-bootstrap';
import {cardArray} from '../cards/cards.js';
import {connect} from 'react-redux'

class CardGrid extends Component {
  constructor(){
    super()
    this.state = {
      showCardInfo: false,
      modalElement: {},
      insufficientFunds: true
    }
    this.disableButton = this.disableButton.bind(this)
  }

  disableButton(element){
    //check if:
    //is their turn
    if(this.props.game.turn !== 'playerOne'){
      this.setState({insufficientFunds: true})
    } else {
        //they are on buy phase
        if(this.props.game.phase !== 'buy'){
          this.setState({insufficientFunds: true})
        } else {
            //they have enough money - if so, all conditions are met
            //and user can buy card
            const turn = this.props.game.turn
            const turnPlayer = this.props.game.players[turn]
            const turnPlayerMoney = turnPlayer.money
            if(turnPlayerMoney < element.cost){
              this.setState({insufficientFunds: true})
            } else{
               this.setState({insufficientFunds: false})
            } 
         }
      }
  }

  render() {
    let close = () => this.setState({showCardInfo: false})

    return (
      <div className="game-grid">
        <CardModal
          game={this.props.game}
          close={() => close()}
          show={this.state.showCardInfo}
          insufficientFunds={this.state.insufficientFunds}
          element={this.state.modalElement}
          quantity={this.props.game.cards[this.state.modalElement.refName]}
        />
        {cardArray.map((element, index) => {
          return (
            <Col sm={4} className="col-lg-5ths card-cont modal-container" key={index}
              onClick={(evt) => {
              console.log('ELEMENT', element)
              evt.preventDefault()
              this.setState({
                showCardInfo: true,
                modalElement: element
              })
              this.disableButton(element)
{'fraction_non_alphanumeric': 0.12943387361992012, 'fraction_numerical': 0.0009396288466055908, 'mean_word_length': 2.179985063480209, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '6408418', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1219, 'n_words': 255}