import PropTypes from 'prop-types';
import Footnote from './Footnote';
import Row from './Row';
import OtherCandidatesRow from './OtherCandidatesRow';
import ResultsContext from './ResultsContext';
import Table from './Table';
import Header from './Header';

/**
 * A table of results for either a contest summary or a single reporting
 * unit.
 */
const ResultsTable = function ResultsTable(props) {
  const {
    id,
    format,
    expandable,
    expandableCutoff,
    disableFooter
  } = props;
  return <ResultsContext format={format} expandable={expandable} id={id} expandableCutoff={expandableCutoff} disableFooter={disableFooter}>
      <Table id={id} />
      <Footnote contestId={id} />
    </ResultsContext>;
};
ResultsTable.Context = ResultsContext;
ResultsTable.SingleCandidatesRow = Row;
ResultsTable.AggregateCandidatesRow = OtherCandidatesRow;
ResultsTable.Header = Header;
ResultsTable.defaultProps = {
  format: 'standard',
  expandable: 'expandableAggregation',
  disableFooter: false,
  expandableCutoff: 2
};
ResultsTable.propTypes = {
  /**
   * The ID of the contest or reporting unit.
   */
  id: PropTypes.string.isRequired,
  /**
   * The format of the results table. This dictates what level of information
   * is available in the results table, as well as the styling of the table.
   */
  format: PropTypes.oneOf(['standard', 'condensed', 'tooltip']),
  /**
   * How the results table should handle additional candidates beyond the few
   * we display by default.
   */
  expandable: PropTypes.oneOf(['expandableAggregation', 'aggregationOnly']),
  /**
   * How many to show before aggregation.
   */
  expandableCutoff: PropTypes.number,
  /**
   * Disable the footer that reports percent in and the incumbent label.
   * Helpful for use in situations when you want to handle displaying that
   * stuff yourself.
   */
  disableFooter: PropTypes.bool
};
export default ResultsTable;