<commit_before>import React from 'react';
import _ from 'lodash/fp';
import classNames from 'classnames';

import ErrorableRadioButtons from '@department-of-veterans-affairs/formation-react/ErrorableRadioButtons';

import environment from '../../../platform/utilities/environment';

const levels = [
  ['newBenefit'],
  ['serviceBenefitBasedOn', 'transferredEduBenefits'],
  ['nationalCallToService', 'sponsorDeceasedDisabledMIA'],
  ['vetTecBenefit'],
  ['sponsorTransferredBenefits'],
];

export default class EducationWizard extends React.Component {
  constructor(props) {
    super(props);

    // flattens all the fields in levels into object keys
    this.state = []
      .concat(...levels)
      .reduce((state, field) => Object.assign(state, { [field]: null }), {
        open: false,
      });
  }

  getButton(form) {
    let url;
    switch (form) {
      case '0994':
        url = `/education/about-gi-bill-benefits/how-to-use-benefits/vettec-high-tech-program/apply-for-vettec-form-22-0994`;
        break;
      default:
        url = `/education/apply-for-education-benefits/application/${form}`;
    }

    return (
      <a
        id="apply-now-link"
        href={url}
        className="usa-button va-button-primary"
      >
        Apply Now
      </a>
    );
  }

  answerQuestion = (field, answer) => {
    const newState = Object.assign({}, { [field]: answer });

    // drop all the levels until we see the current question, then reset
    // everything at that level and beyond, so we don't see questions from
    // different branches
    const fields = [].concat(
      ..._.dropWhile(level => !level.includes(field), levels),
    );
    fields.forEach(laterField => {
      if (laterField !== field) {
        newState[laterField] = null;
      }
    });

    this.setState(newState);
  };

  render() {
    const {
      newBenefit,
      serviceBenefitBasedOn,
      nationalCallToService,
      transferredEduBenefits,
      sponsorDeceasedDisabledMIA,
      sponsorTransferredBenefits,
      vetTecBenefit,
    } = this.state;

    const buttonClasses = classNames('usa-button-primary', 'wizard-button', {
      'va-button-primary': !this.state.open,
    });
    const contentClasses = classNames(
      'form-expanding-group-open',
      'wizard-content',
      {
        'wizard-content-closed': !this.state.open,
      },
    );

    return (
      <div className="wizard-container">
        <button
          aria-expanded={this.state.open ? 'true' : 'false'}
          aria-controls="wizardOptions"
          className={buttonClasses}
          onClick={() => this.setState({ open: !this.state.open })}
        >
          Find your education benefits form
        </button>
        <div className={contentClasses} id="wizardOptions">
          <div className="wizard-content-inner">
            <ErrorableRadioButtons
              additionalFieldsetClass="wizard-fieldset"
              name="newBenefit"
              id="newBenefit"
              options={[
                { label: 'Applying for a new benefit', value: 'yes' },
                {
                  label: 'Updating my current education benefits',
                  value: 'no',
                },
                ...(!environment.isProduction()
                  ? [
                      {
                        label:
                          'Extending my benefit using Edith Nourse Rogers STEM Scholarship',
                        value: 'extend',
                      },
                    ]
                  : []),
              ]}
              onValueChange={({ value }) =>
                this.answerQuestion('newBenefit', value)
              }
              value={{ value: newBenefit }}
              label="Are you applying for a new benefit or updating your current education benefits?"
            />
            {newBenefit === 'yes' && (
              <ErrorableRadioButtons
                additionalFieldsetClass="wizard-fieldset"
                name="serviceBenefitBasedOn"
                id="serviceBenefitBasedOn"
                options={[
                  { label: 'Yes', value: 'own' },
                  { label: 'No', value: 'other' },
                ]}
                onValueChange={({ value }) =>
                  this.answerQuestion('serviceBenefitBasedOn', value)
                }
                value={{ value: serviceBenefitBasedOn }}
                label="Are you a Veteran or service member claiming a benefit based on your own service?"
              />
            )}<commit_msg>19277: STEM: Update Rogers Scholarship Wizard Answer Text (#10394)<commit_after>import React from 'react';
import _ from 'lodash/fp';
import classNames from 'classnames';

import ErrorableRadioButtons from '@department-of-veterans-affairs/formation-react/ErrorableRadioButtons';

import environment from '../../../platform/utilities/environment';

const levels = [
  ['newBenefit'],
  ['serviceBenefitBasedOn', 'transferredEduBenefits'],
  ['nationalCallToService', 'sponsorDeceasedDisabledMIA'],
  ['vetTecBenefit'],
  ['sponsorTransferredBenefits'],
];

export default class EducationWizard extends React.Component {
  constructor(props) {
    super(props);

    // flattens all the fields in levels into object keys
    this.state = []
      .concat(...levels)
      .reduce((state, field) => Object.assign(state, { [field]: null }), {
        open: false,
      });
  }

  getButton(form) {
    let url;
    switch (form) {
      case '0994':
        url = `/education/about-gi-bill-benefits/how-to-use-benefits/vettec-high-tech-program/apply-for-vettec-form-22-0994`;
        break;
      default:
        url = `/education/apply-for-education-benefits/application/${form}`;
    }

    return (
      <a
        id="apply-now-link"
        href={url}
        className="usa-button va-button-primary"
      >
        Apply Now
      </a>
    );
  }

  answerQuestion = (field, answer) => {
    const newState = Object.assign({}, { [field]: answer });

    // drop all the levels until we see the current question, then reset
    // everything at that level and beyond, so we don't see questions from
    // different branches
    const fields = [].concat(
      ..._.dropWhile(level => !level.includes(field), levels),
    );
    fields.forEach(laterField => {
      if (laterField !== field) {
        newState[laterField] = null;
      }
    });

    this.setState(newState);
  };

  render() {
    const {
      newBenefit,
      serviceBenefitBasedOn,
      nationalCallToService,
      transferredEduBenefits,
      sponsorDeceasedDisabledMIA,
      sponsorTransferredBenefits,
      vetTecBenefit,
    } = this.state;

    const buttonClasses = classNames('usa-button-primary', 'wizard-button', {
      'va-button-primary': !this.state.open,
    });
    const contentClasses = classNames(
      'form-expanding-group-open',
      'wizard-content',
      {
        'wizard-content-closed': !this.state.open,
      },
    );

    return (
      <div className="wizard-container">
        <button
          aria-expanded={this.state.open ? 'true' : 'false'}
          aria-controls="wizardOptions"
          className={buttonClasses}
          onClick={() => this.setState({ open: !this.state.open })}
        >
          Find your education benefits form
        </button>
        <div className={contentClasses} id="wizardOptions">
          <div className="wizard-content-inner">
            <ErrorableRadioButtons
              additionalFieldsetClass="wizard-fieldset"
              name="newBenefit"
              id="newBenefit"
              options={[
                { label: 'Applying for a new benefit', value: 'yes' },
                {
                  label: 'Updating my current education benefits',
                  value: 'no',
                },
                ...(!environment.isProduction()
                  ? [
                      {
                        label:
                          'Applying to extend my benefit using the Edith Nourse Rogers STEM Scholarship',
                        value: 'extend',
                      },
                    ]
                  : []),
              ]}
              onValueChange={({ value }) =>
                this.answerQuestion('newBenefit', value)
              }
              value={{ value: newBenefit }}
              label="Are you applying for a new benefit or updating your current education benefits?"
            />
            {newBenefit === 'yes' && (
              <ErrorableRadioButtons
                additionalFieldsetClass="wizard-fieldset"
                name="serviceBenefitBasedOn"
                id="serviceBenefitBasedOn"
                options={[
                  { label: 'Yes', value: 'own' },
                  { label: 'No', value: 'other' },
                ]}
                onValueChange={({ value }) =>
                  this.answerQuestion('serviceBenefitBasedOn', value)
                }
                value={{ value: serviceBenefitBasedOn }}
                label="Are you a Veteran or service member claiming a benefit based on your own service?"
              />
            )}
{'fraction_non_alphanumeric': 0.12202315927463404, 'fraction_numerical': 0.003277255844439589, 'mean_word_length': 1.8449347420758235, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, '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': '6887435', 'n_tokens_mistral': 2579, 'n_tokens_neox': 2461, 'n_words': 533}