<commit_before>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Form, actions } from 'react-redux-form'
import CheckboxDetailsField from 'shared/form/CheckboxDetailsField'
import formProps from 'shared/form/formPropsSelector'
import ErrorAlert from 'marketplace/components/Alerts/ErrorAlert'
import { SellerAssessmentEvidenceReducer } from 'marketplace/reducers'
import AUheadings from '@gov.au/headings/lib/js/react.js'
import styles from './SellerAssessmentCriteriaStage.scss'

const getCriteriaNeeded = (criteriaNeeded, priceMaximum, maxDailyRate) => {
  let adjustedCriteriaNeeded = parseInt(criteriaNeeded, 10)
  if (parseInt(maxDailyRate, 10) > parseInt(priceMaximum, 10)) {
    adjustedCriteriaNeeded += 1
  }
  return adjustedCriteriaNeeded
}

const getCriteriaAllowed = (criteriaNeeded, priceMaximum, maxDailyRate) =>
  getCriteriaNeeded(criteriaNeeded, priceMaximum, maxDailyRate) + 2

const getMinimumMessage = (criteriaNeeded, essentialCriteria) => {
  if (essentialCriteria.length > 0) {
    return (
      <span>
        You must select at least {criteriaNeeded - essentialCriteria.length} <strong>&apos;Other criteria&apos;</strong>
      </span>
    )
  }

  return (
    <span>
      You must submit evidence for at least {criteriaNeeded} {criteriaNeeded === 1 ? 'criterion' : 'criteria'}
    </span>
  )
}

const getMaximumMessage = (criteriaAllowed, essentialCriteria) => {
  if (essentialCriteria.length > 0) {
    return (
      <span>
        You can only select a maximum of {criteriaAllowed - essentialCriteria.length}{' '}
        <strong>&apos;Other criteria&apos;</strong>
      </span>
    )
  }

  return <span>You cannot submit evidence for more than ${criteriaAllowed} criteria.</span>
}

const minimumCriteriaMet = (v, d) =>
  d.criteriaNeeded &&
  v.criteria &&
  v.criteria.length &&
  v.criteria.length >= getCriteriaNeeded(d.criteriaNeeded, d.priceMaximum, v.maxDailyRate)

const maximumCriteriaAllowed = (v, d) =>
  !minimumCriteriaMet(v, d) ||
  new Date(v.created_at) <= new Date(d.criteriaEnforcementCutoffDate) ||
  (d.criteriaNeeded &&
    v.criteria &&
    v.criteria.length &&
    v.criteria.length <= getCriteriaAllowed(d.criteriaNeeded, d.priceMaximum, v.maxDailyRate))

export const done = (formValues, meta) =>
  minimumCriteriaMet(formValues, meta.domain) && maximumCriteriaAllowed(formValues, meta.domain)

class SellerAssessmentCriteriaStage extends Component {
  constructor(props) {
    super(props)
    this.handleClick = this.handleClick.bind(this)
  }

  handleClick(e) {
    // add the selected criteria to the responses model if it doesn't yet exist
    if (e.target.checked) {
      const criteriaId = e.target.value<commit_msg>Fix validation error message by removing dollar symbol (#1023)<commit_after>import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Form, actions } from 'react-redux-form'
import CheckboxDetailsField from 'shared/form/CheckboxDetailsField'
import formProps from 'shared/form/formPropsSelector'
import ErrorAlert from 'marketplace/components/Alerts/ErrorAlert'
import { SellerAssessmentEvidenceReducer } from 'marketplace/reducers'
import AUheadings from '@gov.au/headings/lib/js/react.js'
import styles from './SellerAssessmentCriteriaStage.scss'

const getCriteriaNeeded = (criteriaNeeded, priceMaximum, maxDailyRate) => {
  let adjustedCriteriaNeeded = parseInt(criteriaNeeded, 10)
  if (parseInt(maxDailyRate, 10) > parseInt(priceMaximum, 10)) {
    adjustedCriteriaNeeded += 1
  }
  return adjustedCriteriaNeeded
}

const getCriteriaAllowed = (criteriaNeeded, priceMaximum, maxDailyRate) =>
  getCriteriaNeeded(criteriaNeeded, priceMaximum, maxDailyRate) + 2

const getMinimumMessage = (criteriaNeeded, essentialCriteria) => {
  if (essentialCriteria.length > 0) {
    return (
      <span>
        You must select at least {criteriaNeeded - essentialCriteria.length} <strong>&apos;Other criteria&apos;</strong>
      </span>
    )
  }

  return (
    <span>
      You must submit evidence for at least {criteriaNeeded} {criteriaNeeded === 1 ? 'criterion' : 'criteria'}
    </span>
  )
}

const getMaximumMessage = (criteriaAllowed, essentialCriteria) => {
  if (essentialCriteria.length > 0) {
    return (
      <span>
        You can only select a maximum of {criteriaAllowed - essentialCriteria.length}{' '}
        <strong>&apos;Other criteria&apos;</strong>
      </span>
    )
  }

  return <span>You cannot submit evidence for more than {criteriaAllowed} criteria.</span>
}

const minimumCriteriaMet = (v, d) =>
  d.criteriaNeeded &&
  v.criteria &&
  v.criteria.length &&
  v.criteria.length >= getCriteriaNeeded(d.criteriaNeeded, d.priceMaximum, v.maxDailyRate)

const maximumCriteriaAllowed = (v, d) =>
  !minimumCriteriaMet(v, d) ||
  new Date(v.created_at) <= new Date(d.criteriaEnforcementCutoffDate) ||
  (d.criteriaNeeded &&
    v.criteria &&
    v.criteria.length &&
    v.criteria.length <= getCriteriaAllowed(d.criteriaNeeded, d.priceMaximum, v.maxDailyRate))

export const done = (formValues, meta) =>
  minimumCriteriaMet(formValues, meta.domain) && maximumCriteriaAllowed(formValues, meta.domain)

class SellerAssessmentCriteriaStage extends Component {
  constructor(props) {
    super(props)
    this.handleClick = this.handleClick.bind(this)
  }

  handleClick(e) {
    // add the selected criteria to the responses model if it doesn't yet exist
    if (e.target.checked) {
      const criteriaId = e.target.value
{'fraction_non_alphanumeric': 0.11131059245960502, 'fraction_numerical': 0.00466786355475763, 'mean_word_length': 4.44574780058651, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 49, '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': '6126631', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1698, 'n_words': 405}