import React from 'react';
import { withStyles } from '@material-ui/core/styles';
import ConditionSelector from './ConditionSelector/ConditionSelector';

const styles = theme => ({
  label: {
    margin: theme.spacing.unit * 20
  },
});


class InfectionSelectors extends React.Component {
  state = {
    tb: false
  }

  handleChange = ({ condition, position, value }) => () => {
    const { change, input } = this.props;
    this.setState((prevState) => {
      const checked = !prevState[condition];
      change(`${input.name}[${position}]`, checked && value);
      return ({ [condition]: checked });
    });
  };

  render() {
    const {
      tb,
    } = this.state;

    const { change, patient, recorder } = this.props;

    return (
      <div>
        <ConditionSelector
          subheading="TB"
          checked={tb}
          condition="tb"
          handleChange={this.handleChange}
          code="1B14"
          value="1B14"
          position={7}
          change={change}
          messageId="page.conditions.highBloodPressure"
          recorder={recorder}
          patient={patient}
        />
      </div>
    );
  }
}


export default withStyles(styles)(InfectionSelectors);
