<commit_before># @cjsx React.DOM
React = require 'react'
Draggable       = require '../../lib/draggable'
PrevButton      = require './prev-button'
NextButton      = require './next-button'
DoneButton      = require './done-button'
TranscribeInput = require './transcribe-input'

TranscribeTool = React.createClass
  displayName: 'TranscribeTool'

  getInitialState: ->
    console.log 'PROPS:', @props
    currentStep: 0
    dx: window.innerWidth/2 - 200
    dy: @props.scale.vertical * @props.selectedMark.yLower + 20
    
  # componentWillReceiveProps: ->

  handleTranscription: ->
    console.log 'handleTranscription()'

    transcription = []
    for step, i in @props.transcribeSteps
      transcription.push { field_name: "#{step.field_name}", value: $(".transcribe-input:eq(#{step.key})").val() }

    # field_name = @props.transcribeSteps[@state.currentStep].field_name
    # field_data = $('.transcribe-input').val()

    @props.recordTranscription(transcription)
    @setState currentStep: 0

  nextTextEntry: ->
    @setState
      currentStep: 0
      dx: window.innerWidth/2 - 200
      dy: @props.scale.vertical * @props.selectedMark.yLower + 20, =>
        @props.nextTextEntry()

  nextStep: (e) ->
    return unless @nextStepAvailable()
    @setState currentStep: @state.currentStep + 1

  prevStep: ->
    return unless @prevStepAvailable()
    @setState currentStep: @state.currentStep - 1

  nextStepAvailable: ->
    if @state.currentStep + 1 > @props.transcribeSteps.length - 1
      # console.log 'THERE IS NO NEXT STEP'
      return false
    else
      # console.log 'NEXT STEP...'
      return true

  prevStepAvailable: ->
    if @state.currentStep - 1 >= 0
      return true
    else
      return false

  handleInitStart: (e) ->
    # console.log 'handleInitStart() '
    # console.log 'TARGET: ', e.target.nodeName
    @setState preventDrag: false
    if e.target.nodeName is "INPUT"
      @setState preventDrag: true
      
    console.log "[left, top] = [#{@state.dx}, #{@state.dy}]"

    @setState
      xClick: e.pageX - $('.transcribe-tool').offset().left
      yClick: e.pageY - $('.transcribe-tool').offset().top

  handleInitDrag: (e) ->
    # # DEBUG CODE
    # console.log 'handleInitDrag()'
    # console.log 'OFFSET: ', $('.transcribe-tool').offset()

    return if @state.preventDrag

    dx = e.pageX - @state.xClick - window.scrollX
    dy = e.pageY - @state.yClick - window.scrollY

    @setState
      dx: dx
      dy: dy #, =>
        # console.log "DRAG: [left, top] = [#{@state.dx}, #{@state.dy}]"

  handleInitRelease: -><commit_msg>prevent dragging ui via textarea<commit_after># @cjsx React.DOM
React = require 'react'
Draggable       = require '../../lib/draggable'
PrevButton      = require './prev-button'
NextButton      = require './next-button'
DoneButton      = require './done-button'
TranscribeInput = require './transcribe-input'

TranscribeTool = React.createClass
  displayName: 'TranscribeTool'

  getInitialState: ->
    console.log 'PROPS:', @props
    currentStep: 0
    dx: window.innerWidth/2 - 200
    dy: @props.scale.vertical * @props.selectedMark.yLower + 20
    
  # componentWillReceiveProps: ->

  handleTranscription: ->
    console.log 'handleTranscription()'

    transcription = []
    for step, i in @props.transcribeSteps
      transcription.push { field_name: "#{step.field_name}", value: $(".transcribe-input:eq(#{step.key})").val() }

    # field_name = @props.transcribeSteps[@state.currentStep].field_name
    # field_data = $('.transcribe-input').val()

    @props.recordTranscription(transcription)
    @setState currentStep: 0

  nextTextEntry: ->
    @setState
      currentStep: 0
      dx: window.innerWidth/2 - 200
      dy: @props.scale.vertical * @props.selectedMark.yLower + 20, =>
        @props.nextTextEntry()

  nextStep: (e) ->
    return unless @nextStepAvailable()
    @setState currentStep: @state.currentStep + 1

  prevStep: ->
    return unless @prevStepAvailable()
    @setState currentStep: @state.currentStep - 1

  nextStepAvailable: ->
    if @state.currentStep + 1 > @props.transcribeSteps.length - 1
      # console.log 'THERE IS NO NEXT STEP'
      return false
    else
      # console.log 'NEXT STEP...'
      return true

  prevStepAvailable: ->
    if @state.currentStep - 1 >= 0
      return true
    else
      return false

  handleInitStart: (e) ->
    # console.log 'handleInitStart() '
    # console.log 'TARGET: ', e.target.nodeName
    @setState preventDrag: false
    if e.target.nodeName is "INPUT" or e.target.nodeName is "TEXTAREA"
      @setState preventDrag: true
      
    console.log "[left, top] = [#{@state.dx}, #{@state.dy}]"

    @setState
      xClick: e.pageX - $('.transcribe-tool').offset().left
      yClick: e.pageY - $('.transcribe-tool').offset().top

  handleInitDrag: (e) ->
    # # DEBUG CODE
    # console.log 'handleInitDrag()'
    # console.log 'OFFSET: ', $('.transcribe-tool').offset()

    return if @state.preventDrag # not too happy about this one

    dx = e.pageX - @state.xClick - window.scrollX
    dy = e.pageY - @state.yClick - window.scrollY

    @setState
      dx: dx
      dy: dy #, =>
        # console.log "DRAG: [left, top] = [#{@state.dx}, #{@state.dy}]"

  handleInitRelease: ->
{'fraction_non_alphanumeric': 0.14437892334030816, 'fraction_numerical': 0.007989347536617843, 'mean_word_length': 2.8435672514619883, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '7150413', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1661, 'n_words': 376}