@JamClassSearchHeader = React.createClass({

  mixins: [Reflux.listenTo(@UserStore, "onUserChanged"), Reflux.listenTo(@TeacherSearchStore, "onTeacherSearchStore")]

  onTeacherSearchStore: ()->

  getInitialState: () ->
    {user: null}


  onUserChanged: (@user) ->
    @setState({user: @user?.user})


  createSearchDescription: () ->
    searchOptions = TeacherSearchStore.getState()

    summary = ''

    if searchOptions.onlyMySchool && @state.user?.school_id?
      summary += "From My School Only"

    instruments = searchOptions.instruments
    if instruments? && instruments.length > 0
      if instruments.length == 1
        bit = "Instrument = #{InstrumentStore.display(instruments[0])}"
      else
        instruments.length > 1
        bit = "Instruments = #{InstrumentStore.display(instruments[0])} ... "
      if summary.length > 0
        summary += ', '
      summary += " #{bit}"

    subjects = searchOptions.subjects
    if subjects? && subjects.length > 0
      if subjects.length == 1
        bit = "Subject = #{SubjectStore.display(subjects[0])}"
      else
        subjects.length > 1
        bit = "Subjects = #{SubjectStore.display(subjects[0])} ... "
      if summary.length > 0
        summary += ', '
      summary += " #{bit}"

    genres = searchOptions.genres
    if genres? && genres.length > 0
      if genres.length == 1
        bit = "Genre = #{GenreStore.display(genres[0])}"
      else
        genres.length > 1
        bit = "Genres = #{GenreStore.display(genres[0])} ... "
      if summary.length > 0
        summary += ', '
      summary += " #{bit}"

    languages = searchOptions.languages
    if languages? && languages.length > 0
      if languages.length == 1
        bit = "Language = #{LanguageStore.display(languages[0])}"
      else
        languages.length > 1
        bit = "Languages = #{LanguageStore.display(languages[0])} ... "
      if summary.length > 0
        summary += ', '
      summary += " #{bit}"

    if searchOptions.teaches_beginner || searchOptions.teaches_intermediate || searchOptions.teaches_advanced
      bit = "Teaches "
      qualifier = ''
      if searchOptions.teaches_beginner
        qualifier += "Beginner"
      if searchOptions.teaches_intermediate
        if qualifier.length > 0
          qualifier += ", "
        qualifier += "Intermediate"
      if searchOptions.teaches_advanced
        if qualifier.length > 0
          qualifier += ", "
        qualifier += "Advanced"
      if summary.length > 0
        summary += ', '
      summary += " #{bit}#{qualifier}"

    if searchOptions.student_age?
      if summary.length > 0
        summary += ', '
      summary += "Student Age = #{searchOptions.student_age}"

    if searchOptions.years_teaching?
      if summary.length > 0
        summary += ', '
      summary += "Years Teaching = #{searchOptions.years_teaching}"

    if searchOptions.location?.country?
      if summary.length > 0
        summary += ', '
      summary += "Country = #{searchOptions.location.country}"

    if searchOptions.location?.region?

      if summary.length > 0
        summary += ', '
      summary += "Region = #{searchOptions.location.region}"


    if summary.length == 0
      summary = 'all teachers'

    summary


  render: () ->
    searchDesc = @createSearchDescription()

    if @props.teacher
      complete = `<span className="search-results-options">
          <a href="/client#/teachers/search" className="results-text link">Search Results</a>&nbsp;:&nbsp;
          <span className="teacher-name">{this.props.teacher.name}</span>
      </span>`
    else
      complete =
        `<span className="search-results-options">
          <span className="search-description">
            <span className="results-text">Search Results / </span>
            <span className="search-summary">{searchDesc}</span>
            </span>
          </span>`
    `<div className="jamclass-search-header">
      <a href="/client#/home">JamKazam Home</a>&nbsp;:&nbsp;
      <a href="/client#/jamclass">JamClass Home</a>&nbsp;:&nbsp;
      <a className="teacher-search-options" href="/client#/jamclass/searchOptions">Teachers Search</a><span
      className="teacher-quote"> : </span>
      {complete}
    </div>`
})