 {Link}                  = require 'react-router'
 YaleTutorial            = require '../yale-tutorial'
 YaleMarkTutorialText    = require '../tutorial-text/yale-mark-tutorial-text'
+BooleanToggle           = require './tools/boolean-toggle/boolean-toggle'
+Classification          = require 'models/classification.coffee'
 
 module.exports = React.createClass # rename to Classifier
   displayName: 'Mark'

                />

                <div className="task-button-container">
                  <nav className="task-nav">
                    { if false
                      <button type="button" className="back minor-button" disabled={onFirstAnnotation} onClick={@destroyCurrentAnnotation}>Back</button>
                    }
                    { if @getNextTask() and @state.badSubject != true?
                        <button type="button" className="continue major-button" disabled={waitingForAnswer} onClick={@advanceToNextTask}>Next</button>
                      else
                        if @state.taskKey == "completion_assessment_task"
                          if @getCurrentSubject() == @getCurrentSubjectSet().subjects[@getCurrentSubjectSet().subjects.length-1]
                            <button type="button" className="continue major-button" disabled={waitingForAnswer} onClick={@completeSubjectAssessment}>Next</button>
                          else
                            <button type="button" className="continue major-button" disabled={waitingForAnswer} onClick={@completeSubjectAssessment}>Next Program</button>
                        else
                          <button type="button" className="continue major-button" disabled={waitingForAnswer} onClick={@completeSubjectSet}>Done</button>
                    }
                  </nav>

                  <div className="help-bad-subject-holder">
                    { if @getCurrentTask().help?

  hideSubjectHelp: () ->
    @setState
      activeSubjectHelper: null

  # This method should be called when users click a button that indicates they're done with this
  # playbill. Once this action is called, we check to see the current state of the boolean toggle
  # that indicates whether the user has marked all fields in this subject set. If they have,
  # we send the server a POST request with an annotation task_key "completion_assessment_task"
  # (i.e. the annotation task that indicates whether a subject set has been fully marked by the user)
  # with a value of "complete_subject". If the user did not indicate they've marked every field
  # in this record, the POST request indicates the user has not marked everything
  completeThisSubjectSetAndGetAnother: () ->
    # create and post an annotation that indicates the current state of the boolean toggle
    classification = new Classification()

    if @state.markingIsDone == 1
      classification.annotation = {value: "complete_subject"}
    else
      classification.annotation = {value: "incomplete_subject"}

    classification.subject_id = @getCurrentSubject()?.id
    classification.subject_set_id = @getCurrentSubjectSet().id if @getCurrentSubjectSet()?
    classification.workflow_id = @getActiveWorkflow().id
    if @state.badSubject
      classification.task_key = 'flag_bad_subject_task'
    else if @state.illegibleSubject
      classification.task_key = 'flag_illegible_subject_task'
    else
      classification.task_key = "completion_assessment_task"

    @commitClassification(classification)
    @advanceToNextSubject()

    # after submitting the completion_assessment_task, ensure the boolean toggle
    # that indicates whether the user has marked everything is marked as "No"
    @setState(markingIsDone: 0)


  updateBooleanToggle: () ->
    if @state.markingIsDone == 0
      @setState
        markingIsDone: 1

    else
      @setState
        markingIsDone: 0

  render: ->
    return null unless @getCurrentSubjectSet()? && @getActiveWorkflow()?
