(function (context, $) {

  "use strict";

  context.JK = context.JK || {};
  context.JK.StepConfigureTracks = function (app) {

    var ASSIGNMENT = context.JK.ASSIGNMENT;
    var VOICE_CHAT = context.JK.VOICE_CHAT;
    var MAX_TRACKS = context.JK.MAX_TRACKS;

    var logger = context.JK.logger;
    var configureTracksHelper = new context.JK.ConfigureTracksHelper(app);

    var $step = null;
    var $watchVideoBtn = null;
    var successfullyAssignedOnce = false;
    var wizard = null;
    var firstTime = true;
    var helpTimeout = null;
    var operatingSystem = null;


    function handleHelp() {
      if (operatingSystem == "Win32") {
        return "https://jamkazam.freshdesk.com/support/solutions/articles/66000123618-setup-wizard-windows-step-3-configuring-your-audio-input-tracks"
      }
      else {
        return "https://jamkazam.freshdesk.com/support/solutions/articles/66000123593-setup-wizard-mac-step-3-configuring-your-audio-input-tracks"
      }
    }

    function handleNext() {
     /** var saved = configureTracksHelper.trySave();

      if(saved) {
        context.JK.GA.trackConfigureTracksCompletion(context.JK.detectOS());
        successfullyAssignedOnce = true;
      }
*/
      if (helpTimeout) {
        clearTimeout(helpTimeout);
      }
      return context.ConfigureTracksStore.editingTrackValid()
    }

    function newSession() {
      successfullyAssignedOnce = false;
    }

    function beforeShow() {
      var forceInputsToUnassigned = !successfullyAssignedOnce;

      window.ConfigureTracksActions.reset(false);
      //configureTracksHelper.reset(forceInputsToUnassigned, wizard.getChosenInputs())

      prodInstructions();
    }

    function prodInstructions() {
      if (firstTime && !helpTimeout) {

        helpTimeout = setTimeout(function() {
          helpTimeout = null
          firstTime = false;

          context.JK.HelpBubbleHelper.ftueStep3ConfigTracks($watchVideoBtn)
        }, 2000)
      }
    }
    function initialize(_$step, _wizard, _operatingSystem) {
      $step = _$step;
      wizard = _wizard;
      operatingSystem = _operatingSystem;
      $watchVideoBtn = $step.find('.watch-video')
      $watchVideoBtn.attr('href', handleHelp())

      configureTracksHelper.initialize($step);
    }

    this.handleHelp = handleHelp;
    this.newSession = newSession;
    this.handleNext = handleNext;
    this.beforeShow = beforeShow;
    this.initialize = initialize;

    return this;
  }
})(window, jQuery);