context = window
rest = context.JK.Rest()
logger = context.JK.logger

AttachmentStore = context.AttachmentStore

@AttachmentStatus = React.createClass({

  mixins: [
    Reflux.listenTo(AttachmentStore, "onAttachmentStore"),
  ]

  onAttachmentStore: (attachmentState) ->

  componentDidMount: () ->
    @root = $(@getDOMNode())
    @attachmentNotation = @root.find('.attachment-notation')
    @attachmentAudio = @root.find('.attachment-audio')

  notationSelected: (e) ->
    files = $(e.target).get(0).files
    logger.debug("notation files selected: ", files)
    window.AttachmentActions.uploadNotations.trigger(files, @notationUploadDone, @notationUploadFail)

  notationUploadDone: () ->
    logger.debug("AttachmentStatus: notationUploadDone")
    #context.JK.Banner.showNotice('Notation Uploaded', 'The music notation file has been uploaded, and can be accessed from the Messages window for this lesson.')

  notationUploadFail: () ->
    logger.debug("AttachmentStatus: notationUploadFail")

  audioSelected: (e) ->
    files = $(e.target).get(0).files
    logger.debug("audio files selected: ", files)
    window.AttachmentActions.uploadAudios.trigger(files, @notationUploadDone, @notationUploadFail)

  audioUploadDone: () ->
    logger.debug("AttachmentStatus: audioUploadDone")
    #context.JK.Banner.showNotice('Audio file Uploaded', 'The audio file has been uploaded, and can be accessed from the Messages window for this lesson.')

  audioUploadFail: () ->
    logger.debug("AttachmentStatus: audioUploadFail")


  render: () ->
    `<div className="attachment-status">

      <form className="hidden">
        <input type="file" className="hidden attachment-notation" value="" onChange={this.notationSelected}
               accept=".pdf, .png, .jpg, .jpeg, .gif, .xml, .mxl, .txt" multiple/>
        <input type="file" className="hidden attachment-audio" value="" onChange={this.audioSelected}
               accept=".wav, .flac, .ogg, .aiff, .aifc, .au" multiple/>
      </form>
    </div>`

})

