<commit_before>/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import { connect } from 'react-redux';

import { updateBenefitSummaryRequestOption } from '../actions/letters';
import {
  benefitOptionsMap,
  characterOfServiceContent,
  optionsToAlwaysDisplay,
  getBenefitOptionText
} from '../utils/helpers.jsx';
import { formatDateShort } from '../../common/utils/helpers';

export class VeteranBenefitSummaryLetter extends React.Component {
  constructor() {
    super();
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(domEvent) {
    window.dataLayer.push({
      event: 'letter-benefit-option-clicked',
      'letter-benefit-option': domEvent.target.id,
      'letter-benefit-option-status': domEvent.target.checked ? 'checked' : 'unchecked'
    });
    this.props.updateBenefitSummaryRequestOption(
      benefitOptionsMap[domEvent.target.id],
      domEvent.target.checked);
  }

  render() {
    const serviceInfo = this.props.benefitSummaryOptions.serviceInfo || [];
    const militaryServiceRows = serviceInfo.map((service, index) => {
      return (
        <tr key={`service${index}`}>
          <th scope="row" className="service-info">{(service.branch || '').toLowerCase()}</th>
          <td className="service-info">
            {characterOfServiceContent[(service.characterOfService || '').toLowerCase()]}
          </td>
          <td>{formatDateShort(service.enteredDate)}</td>
          <td>{formatDateShort(service.releasedDate)}</td>
        </tr>
      );
    });
    
    const benefitInfo = this.props.benefitSummaryOptions.benefitInfo;
    const requestOptions = this.props.requestOptions;
    let vaBenefitInformation;
    const vaBenefitInfoRows = [];

    Object.keys(benefitInfo).forEach(key => {
      // Need to verify with EVSS and vets-api: values should be true, false, or
      // some value other than null or undefined, so this check should not be
      // necessary, or should log a Sentry error.
      if (benefitInfo[key] === null) {
        return;
      }
      // For some options, the customization checkbox is only displayed
      // if the benefit information value is not false. For others, the
      // customization checkbox is always displayed.
      const value = benefitInfo[key];
      const displayOption = optionsToAlwaysDisplay.includes(key) || value !== false;
      const optionText = getBenefitOptionText(key, value, true, benefitInfo.awardEffectiveDate);
      if (optionText && displayOption) {
        vaBenefitInfoRows.push(
          <tr key={`option${key}`}>
            <th scope="row">
              <input
                aria-labelledby={`${key}Label`}
                autoComplete="false"
                checked={requestOptions[benefitOptionsMap[key]]}
                id={key}
                name={key}
                type="checkbox"
                onChange={this.handleChange}/>
              <label/>
            </th><commit_msg>Replace hardcoded isVeteran with value from store<commit_after>/* eslint-disable jsx-a11y/label-has-for */
import React from 'react';
import { connect } from 'react-redux';

import { updateBenefitSummaryRequestOption } from '../actions/letters';
import {
  benefitOptionsMap,
  characterOfServiceContent,
  optionsToAlwaysDisplay,
  getBenefitOptionText
} from '../utils/helpers.jsx';
import { formatDateShort } from '../../common/utils/helpers';

export class VeteranBenefitSummaryLetter extends React.Component {
  constructor() {
    super();
    this.handleChange = this.handleChange.bind(this);
  }

  handleChange(domEvent) {
    window.dataLayer.push({
      event: 'letter-benefit-option-clicked',
      'letter-benefit-option': domEvent.target.id,
      'letter-benefit-option-status': domEvent.target.checked ? 'checked' : 'unchecked'
    });
    this.props.updateBenefitSummaryRequestOption(
      benefitOptionsMap[domEvent.target.id],
      domEvent.target.checked);
  }

  render() {
    const serviceInfo = this.props.benefitSummaryOptions.serviceInfo || [];
    const militaryServiceRows = serviceInfo.map((service, index) => {
      return (
        <tr key={`service${index}`}>
          <th scope="row" className="service-info">{(service.branch || '').toLowerCase()}</th>
          <td className="service-info">
            {characterOfServiceContent[(service.characterOfService || '').toLowerCase()]}
          </td>
          <td>{formatDateShort(service.enteredDate)}</td>
          <td>{formatDateShort(service.releasedDate)}</td>
        </tr>
      );
    });
    
    const benefitInfo = this.props.benefitSummaryOptions.benefitInfo;
    const requestOptions = this.props.requestOptions;
    let vaBenefitInformation;
    const vaBenefitInfoRows = [];

    Object.keys(benefitInfo).forEach(key => {
      // Need to verify with EVSS and vets-api: values should be true, false, or
      // some value other than null or undefined, so this check should not be
      // necessary, or should log a Sentry error.
      if (benefitInfo[key] === null) {
        return;
      }
      // For some options, the customization checkbox is only displayed
      // if the benefit information value is not false. For others, the
      // customization checkbox is always displayed.
      const value = benefitInfo[key];
      const displayOption = optionsToAlwaysDisplay.includes(key) || value !== false;
      const { isVeteran } = this.props;
      const optionText = getBenefitOptionText(key, value, isVeteran, benefitInfo.awardEffectiveDate);
      if (optionText && displayOption) {
        vaBenefitInfoRows.push(
          <tr key={`option${key}`}>
            <th scope="row">
              <input
                aria-labelledby={`${key}Label`}
                autoComplete="false"
                checked={requestOptions[benefitOptionsMap[key]]}
                id={key}
                name={key}
                type="checkbox"
                onChange={this.handleChange}/>
              <label/>
            </th>
{'fraction_non_alphanumeric': 0.12456228114057029, 'fraction_numerical': 0.0006670001667500417, 'mean_word_length': 2.7675879396984926, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, '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': '253860', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1662, 'n_words': 360}