context = window
ConfigureTracksStore = @ConfigureTracksStore
ConfigureTracksActions = @ConfigureTracksActions
@TryTestDriveDialog = React.createClass({

  mixins: [Reflux.listenTo(@AppStore, "onAppInit")]
  teacher: null

  beforeShow: (args) ->
    # d1 should be a teacher ID (vs a user ID that happens to be a teacher)
    logger.debug("TryTestDriveDialog.beforeShow", args.d1)
    @teacher = args.d1

  afterHide: () ->

  onAppInit: (@app) ->
    dialogBindings = {
      'beforeShow': @beforeShow,
      'afterHide': @afterHide
    };

    @app.bindDialog('try-test-drive', dialogBindings);

  getInitialState: () ->
    {}

  doCancel: (e) ->
    e.preventDefault()
    @app.layout.closeDialog('try-test-drive', true);

  doTestDriveNow: (e) ->
    e.preventDefault()

    rest.createTeacherIntent({id: @teacher, intent: 'book-test-drive'}).done((response) => @marked(response)).fail((jqXHR) => @failedMark(jqXHR))

  marked: () ->
    @app.layout.closeDialog('try-test-drive')
    window.location.href = "/client#/jamclass/lesson-payment/test-drive"

  failedMark: (jqXHR, textStatus, errorMessage) ->
    @app.ajaxError(jqXHR, textStatus, errorMessage)

  render: () ->
    `<div>
      <div className="content-head">
        <img className="content-icon" src="/assets/content/icon_add.png" height={19} width={19}/>

        <h1>TestDrive</h1>
      </div>
      <div className="dialog-inner">

        <h3>What Is TestDrive?</h3>

        <p>
          Our TestDrive package is the best way to painlessly find the best instructor for you - i.e. a teacher who has
          the qualifications you're looking for, and with whom you really connect. This is the most critical factor in
          achieving the results you want from your investment of time and money into lessons.</p>

        <p>With TestDrive you pay just $49.99 to take 4 full lessons - one lesson with each of 4 different teachers you
          select. Then you can pick the teacher who works best for you. It's an amazing value, highly convenient, and
          the best way to find the right teacher for you.</p>

        <p>If you're serious about getting started on lessons, this is the way to go.</p>

        <div className="actions">
          <a onClick={this.doCancel} className="button-grey">CANCEL</a>
          <a onClick={this.doTestDriveNow} className="button-orange purchase-testdrive-now">PURCHASE TESTDRIVE NOW</a>
        </div>
      </div>
    </div>`

  inputChanged: (e) ->
    $root = $(@getDOMNode())

  deletePath: (path, e) ->
    e.preventDefault()

    ConfigureTracksActions.removeSearchPath(path)

  selectVSTDirectory: (e) ->
    e.preventDefault()

    ConfigureTracksActions.selectVSTDirectory()

  doClose: (e) ->
    e.preventDefault()

    @app.layout.closeDialog('try-test-drive', true)

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

  componentWillUpdate: () ->
    @ignoreICheck = true
    $root = $(@getDOMNode())

  componentDidUpdate: () ->
    $root = $(@getDOMNode())
})