 React = require 'react'
 classnames = require 'classnames'
-qs = require 'qs'
+
+Router = require '../router'
 
 # Used to cancel router transitions the same way an onClick event is
 class FakeEvent


  # callable from the parent component via a ref
  selectTabIndex: (activeIndex) ->
    @context.router.transitionTo(pathname: location.pathname, query: {tab: activeIndex})
    @setState({activeIndex})

  onTabClick: (activeIndex, ev) ->

    tabs: React.PropTypes.arrayOf(
      React.PropTypes.oneOfType([ React.PropTypes.string, React.PropTypes.element ])
    ).isRequired
    windowImpl: React.PropTypes.object

  getDefaultProps: ->
    windowImpl: window
    initialActive: 0

  contextTypes:
    router: React.PropTypes.object

  getInitialState: ->
    {tab} = Router.getQuery(@props.windowImpl)
    activeIndex: if _.isUndefined(tab) then @props.initialActive else parseInt(tab, 10)

  componentWillMount: ->
