 {sugarClient} = require 'panoptes-client/lib/sugar'
 classNames = require 'classnames'
 getWorkflowsInOrder = require '../../lib/get-workflows-in-order'
+isAdmin = require '../../lib/is-admin'
 
 counterpart.registerTranslations 'en',
   project:

      .then (pages) =>
        @setState {pages}

  getAllWorkflows: (project) ->
    @setState { loadingSelectedWorkflow: true }

    getWorkflowsInOrder(project, { active: true })
      .then (activeWorkflows) =>
        @setState { activeWorkflows }
      .then =>

        @getSelectedWorkflow(project, @props.preferences)

  getSelectedWorkflow: (project, preferences) ->
    # preference workflow query, then user selected workflow, then project owner set workflow, then default workflow
    # if none of those are set, select random workflow
    if @props.location.query?.workflow? and ('allow workflow query' in @props.project.experimental_tools or @checkUserRoles(project, @props.user))
      preferredWorkflowID = @props.location.query.workflow
      unless preferences?.preferences.selected_workflow is preferredWorkflowID
        @props.onChangePreferences 'preferences.selected_workflow', preferredWorkflowID
