<commit_before>import React, { PropTypes } from 'react'
import Select from 'react-select'
import { Button } from 'react-bootstrap';
import 'react-select/dist/react-select.css'
import ArrayCheckbox from '../../../components/ArrayCheckbox'
import {
  LANGUAGE_CHOICES,
  ETHNICITY_CHOICES,
  MEDICAL_CHOICES,
  SUPPORT_CHOICES,
  PRIMARY_HEALTHCARE_CHOICES,
  LENGTH_OF_HOMELESSNESS_CHOICES
} from '../constants/check-in'
import classes from './CheckInForm.scss'

export const CheckInForm = (props) => {
  let {
    fields: {
      firstName, lastName, socialSecurityNumber, dateOfBirth, phoneNumber, emailAddress,
      gender, isTransexual, isLGBTQ,
      ethnicity, ethnicityOther,
      language, languageOther,
      hasBeenInFosterCare,
      hasServedInTheMilitary,
      primaryHealthcareLocation,
      isHomeless, lengthOfHomelessness,
      medicalServices, supportServices,
    },
    resetForm,
    handleSubmit,
    requesting,
    currentAccount,
  } = props

  // initialize array fields to empty arrays
  ethnicity.value = ethnicity.value || []
  medicalServices.value = medicalServices.value || []
  supportServices.value = supportServices.value || []

  const _onSubmit = () => {
    const fields = props.fields
    const newFields = {}

    for (let field in fields) {

      // skip alt fields, which have their own handlers to update fields correctly
      if (field.endsWith('Other')) continue

      // deal with checkboxes, and checkbox-like inputs differently
      if (fields[field].checked !== undefined) {
        newFields[field] = fields[field].checked
      } else if (fields[field].value !== ""){
        newFields[field] = fields[field].value
      }

    }

    props.updateInfo(newFields, currentAccount && currentAccount.id)
  }

  const _onClear = () => {
    props.clearInfo()
  }

  if (currentAccount) {
    if (currentAccount.firstName) {
      firstName.disabled = true;
    } else {
      delete firstName.disabled;
    }

    if (currentAccount.lastName) {
      lastName.disabled = true;
    } else {
      delete lastName.disabled;
    }

    if (currentAccount.socialSecurityNumber && currentAccount.socialSecurityNumber.length === 9) {
      socialSecurityNumber.disabled = true;
    } else {
      delete socialSecurityNumber.disabled;
    }

    if (currentAccount.dateOfBirth) {
      dateOfBirth.disabled = true;
    } else {
      delete dateOfBirth.disabled;
    }
  }

  return (
    <form onSubmit={handleSubmit(_onSubmit)}>

      <div className={classes.basic + " " + classes.section}>
        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>First Name {firstName.touched && firstName.error && <span className={classes.errorMessage}>{firstName.error}</span>}</label>
          <input className={classes.textInput} type="text" {...firstName} />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Last Name {lastName.touched && lastName.error && <span className={classes.errorMessage}>{lastName.error}</span>}</label>
          <input className={classes.textInput} type="text" {...lastName} />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Social Security Number {socialSecurityNumber.touched && socialSecurityNumber.error && <span className={classes.errorMessage}>{socialSecurityNumber.error}</span>}</label>
          <input
            className={classes.textInput}
            type="phone"
            {...socialSecurityNumber}
          />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Date of Birth (mm-dd-yyyy) {dateOfBirth.touched && dateOfBirth.error && <span className={classes.errorMessage}>{dateOfBirth.error}</span>}</label>
          <input
            className={classes.textInput}
            type="phone"
            {...dateOfBirth}
          />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Phone {phoneNumber.touched && phoneNumber.error && <span className={classes.errorMessage}>{phoneNumber.error}</span>}</label>
          <input className={classes.textInput} type="phone" {...phoneNumber} />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Email Address {emailAddress.touched && emailAddress.error && <span className={classes.errorMessage}>{emailAddress.error}</span>}</label>
          <input className={classes.textInput} type="email" {...emailAddress} />
        </div>
      </div>

      <div className={classes.gender + " " + classes.section}>
        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Gender</label>

          <div className={classes.horizontalInputs}>
            <div className={classes.toggleInputGroup}>
              <label>
                <input
                  {...gender}
                  type="radio"
                  value="male"
                  checked={gender.value === "Male"}
                />
                Male
              </label>
            </div>

            <div className={classes.toggleInputGroup}>
              <label>
                <input
                  {...gender}
                  type="radio"
                  value="female"
                  checked={gender.value === "Female"}
                />
                Female
              </label>
            </div>
          </div>

          <div className={classes.horizontalInputs}>
            <div className={classes.toggleInputGroup}>
              <label>
                <input type="checkbox" {...isTransexual} />
                Different from birth gender?
              </label>
            </div>
          </div>

          {gender.touched && gender.error && <span className={classes.errorMessage}>{gender.error}</span>}
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Sexuality</label>

          <div className={classes.toggleInputGroup}><commit_msg>Make gender selectable again<commit_after>import React, { PropTypes } from 'react'
import Select from 'react-select'
import { Button } from 'react-bootstrap';
import 'react-select/dist/react-select.css'
import ArrayCheckbox from '../../../components/ArrayCheckbox'
import {
  LANGUAGE_CHOICES,
  ETHNICITY_CHOICES,
  MEDICAL_CHOICES,
  SUPPORT_CHOICES,
  PRIMARY_HEALTHCARE_CHOICES,
  LENGTH_OF_HOMELESSNESS_CHOICES
} from '../constants/check-in'
import classes from './CheckInForm.scss'

export const CheckInForm = (props) => {
  let {
    fields: {
      firstName, lastName, socialSecurityNumber, dateOfBirth, phoneNumber, emailAddress,
      gender, isTransexual, isLGBTQ,
      ethnicity, ethnicityOther,
      language, languageOther,
      hasBeenInFosterCare,
      hasServedInTheMilitary,
      primaryHealthcareLocation,
      isHomeless, lengthOfHomelessness,
      medicalServices, supportServices,
    },
    resetForm,
    handleSubmit,
    requesting,
    currentAccount,
  } = props

  // initialize array fields to empty arrays
  ethnicity.value = ethnicity.value || []
  medicalServices.value = medicalServices.value || []
  supportServices.value = supportServices.value || []

  const _onSubmit = () => {
    const fields = props.fields
    const newFields = {}

    for (let field in fields) {

      // skip alt fields, which have their own handlers to update fields correctly
      if (field.endsWith('Other')) continue

      // deal with checkboxes, and checkbox-like inputs differently
      if (fields[field].checked !== undefined) {
        newFields[field] = fields[field].checked
      } else if (fields[field].value !== ""){
        newFields[field] = fields[field].value
      }

    }

    props.updateInfo(newFields, currentAccount && currentAccount.id)
  }

  const _onClear = () => {
    props.clearInfo()
  }

  if (currentAccount) {
    if (currentAccount.firstName) {
      firstName.disabled = true;
    } else {
      delete firstName.disabled;
    }

    if (currentAccount.lastName) {
      lastName.disabled = true;
    } else {
      delete lastName.disabled;
    }

    if (currentAccount.socialSecurityNumber && currentAccount.socialSecurityNumber.length === 9) {
      socialSecurityNumber.disabled = true;
    } else {
      delete socialSecurityNumber.disabled;
    }

    if (currentAccount.dateOfBirth) {
      dateOfBirth.disabled = true;
    } else {
      delete dateOfBirth.disabled;
    }
  }

  return (
    <form onSubmit={handleSubmit(_onSubmit)}>

      <div className={classes.basic + " " + classes.section}>
        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>First Name {firstName.touched && firstName.error && <span className={classes.errorMessage}>{firstName.error}</span>}</label>
          <input className={classes.textInput} type="text" {...firstName} />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Last Name {lastName.touched && lastName.error && <span className={classes.errorMessage}>{lastName.error}</span>}</label>
          <input className={classes.textInput} type="text" {...lastName} />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Social Security Number {socialSecurityNumber.touched && socialSecurityNumber.error && <span className={classes.errorMessage}>{socialSecurityNumber.error}</span>}</label>
          <input
            className={classes.textInput}
            type="phone"
            {...socialSecurityNumber}
          />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Date of Birth (mm-dd-yyyy) {dateOfBirth.touched && dateOfBirth.error && <span className={classes.errorMessage}>{dateOfBirth.error}</span>}</label>
          <input
            className={classes.textInput}
            type="phone"
            {...dateOfBirth}
          />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Phone {phoneNumber.touched && phoneNumber.error && <span className={classes.errorMessage}>{phoneNumber.error}</span>}</label>
          <input className={classes.textInput} type="phone" {...phoneNumber} />
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Email Address {emailAddress.touched && emailAddress.error && <span className={classes.errorMessage}>{emailAddress.error}</span>}</label>
          <input className={classes.textInput} type="email" {...emailAddress} />
        </div>
      </div>

      <div className={classes.gender + " " + classes.section}>
        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Gender</label>

          <div className={classes.horizontalInputs}>
            <div className={classes.toggleInputGroup}>
              <label>
                <input
                  {...gender}
                  type="radio"
                  value="Male"
                  checked={gender.value === "Male"}
                />
                Male
              </label>
            </div>

            <div className={classes.toggleInputGroup}>
              <label>
                <input
                  {...gender}
                  type="radio"
                  value="Female"
                  checked={gender.value === "Female"}
                />
                Female
              </label>
            </div>
          </div>

          <div className={classes.horizontalInputs}>
            <div className={classes.toggleInputGroup}>
              <label>
                <input type="checkbox" {...isTransexual} />
                Different from birth gender?
              </label>
            </div>
          </div>

          {gender.touched && gender.error && <span className={classes.errorMessage}>{gender.error}</span>}
        </div>

        <div className={classes.inputGroup}>
          <label className={classes.fieldName}>Sexuality</label>

          <div className={classes.toggleInputGroup}>
{'fraction_non_alphanumeric': 0.12887906329321214, 'fraction_numerical': 0.00016375992794563171, 'mean_word_length': 2.4155480984340043, 'pattern_counts': {'":': 0, '<': 153, '<?xml version=': 0, '>': 159, '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': '4254421', 'n_tokens_mistral': 3366, 'n_tokens_neox': 3212, 'n_words': 622}