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

AvatarStore = context.AvatarStore

@AvatarEditLink = React.createClass({

  mixins: [
    Reflux.listenTo(AvatarStore, "onAvatarUpdate"),
  ]

  onAvatarUpdate: (avatar) ->
    @setState({avatar: avatar})

  getInitialState: () ->
    {
    avatar: null,
    imageLoadedFpfile: null
    }

  componentWillMount: () ->


  componentDidMount: () ->
    @root = $(@getDOMNode())

  startUpdate: () ->
    AvatarActions.start(this.props.target, this.props.target_type)

  render: () ->
    if this.props.target?.photo_url?

      target_type = this.props.target_type

      testStudentUrl = "/#{target_type}/#{this.props.target.id}/student?preview=true"
      testTeacherUrl = "/#{target_type}/#{this.props.target.id}/teacher?preview=true"

      if target_type == 'school'
        previewArea = `<div className="hint">See how it will look to&nbsp;
          <a href={testStudentUrl} target="_blank">students</a> and&nbsp;
          <a href={testTeacherUrl} target="_blank">teachers</a>
        </div>`
      else
        previewArea = `<div className="hint">See how it will look to&nbsp;
          <a href={testTeacherUrl} target="_blank">teachers</a>
        </div>`


      `<div className="avatar-edit-link">
        <img src={this.props.target.photo_url}></img>
        <br/>
        <a onClick={this.startUpdate}>change/update logo</a><br/>

        {previewArea}
      </div>`
    else
      `<div className="avatar-edit-link">
        <div className="no-avatar-space">
          No logo graphic uploaded
        </div>
        <a onClick={this.startUpdate}>change/update logo</a>
      </div>`

})