 View = require './view'
+
+Requests = require '../collections/Requests'
 
 class GlobalSearchView extends View
 

        @$('input').on 'typeahead:selected', (event, requestId) =>
            @hide()
            app.router.navigate "/request/#{ requestId }", { trigger: true }
            
    reset: ->
        @$('input').val ''
        @$('ul').removeClass 'dropdown-menu-hidden'
        @$('li').remove()

    show: ->
        @reset()
        @$el.parent().addClass 'global-search-active'
        @$('input').focus()

    hide: (event) ->
        if event?


            @lastSearchQuery = query

            fuse = new Fuse(
                @requests.toJSON()
                keys: ["request.id"]
                threshold: 0.6
                id: "request.id")
            results = fuse.search(query)

            process results.slice(0, 10)

        # Debounce event so we don't spam the server
        sourceFunction = _.debounce sourceFunction, 200

        @$('input').typeahead
            highlight: true
        ,
            source: sourceFunction
