{"size": 1227, "ext": "js", "max_stars_repo_path": "src/components/KegDetail.js", "max_stars_repo_name": "cschweig2/kombucha-taproom-redux", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/KegDetail.js", "max_issues_repo_name": "cschweig2/kombucha-taproom-redux", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/KegDetail.js", "max_forks_repo_name": "cschweig2/kombucha-taproom-redux", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.8863636364, "max_line_length": 89, "alphanum_fraction": 0.630806846}
import React from 'react';
import PropTypes from 'prop-types';

function KegDetail(props) {
  const { keg, onClickingDelete, onClickingEdit } = props;
  let newPintsLeft = keg.pintsLeft;
  if (parseInt(newPintsLeft) === 0) {
    newPintsLeft = "Sold Out";
  }

  function handleBuyPintButton(keg, num) {
    num = parseInt(num);
    props.onChangingKegPintsLeft({
      name: keg.name,
      brand: keg.brand,
      flavor: keg.flavor,
      price: keg.price,
      pintsLeft: keg.pintsLeft === 0 ? 0 : keg.pintsLeft = parseInt(keg.pintsLeft) - num,
      id: keg.id
    });
  }
  return (
    <>
      <h1>Keg Details</h1>
      <h2>{keg.brand} - {keg.name}</h2>
      <h3>flavor profile: {keg.flavor}</h3>
      <h4>price: {keg.price}</h4>
      <h4>pints left: {newPintsLeft}</h4>
      <button onClick={ () => onClickingDelete(keg.id) }>Delete Keg</button>
      <button onClick={ () => onClickingEdit(keg.id)}>Edit Keg</button>
      <button onClick={ () => handleBuyPintButton(keg, 1)}>Buy Pint</button>
      <hr />
    </>
  );
}

KegDetail.propTypes = {
  keg: PropTypes.object,
  onClickingDelete: PropTypes.func,
  onClickingEdit: PropTypes.func,
  onChangingKegPintsLeft: PropTypes.func
}

export default KegDetail;