 #
 # TODO:
-# - automatic uname/site fill
 # - green acknowledgment on password change
 #
 # LATER:

#
# BUGS: 
# - feedly -> twitter...
#

re_self      = require('sdk/self')


class AutoFiller
  constructor: () ->
    @tabs = {}

  start: (tab) ->
    if @tabs[tab.id]
      #if only switch tabs...
      return

    console.log "start"
    @tabs[tab.id] = tab.attach
      contentScriptFile: [
        re_self.data.url('jquery.min.js')
        re_self.data.url('input-get.js')
      ]

    tabs_port = @tabs[tab.id].port

    tabs_port.emit 'enable', tab.url
    tabs_port.on 'username', (uname, url) ->
      console.log 'gaining for: ', uname, url
      get_pass uname, url, (p) ->
        tabs_port.emit 'pass', p

  stop: (tab) ->
    if @tabs[tab.id]
      @tabs[tab.id].destroy()
      console.log "stop"

    delete @tabs[tab.id]

  apply_stat: (stat, tab) ->
    if stat == 0
      @.start tab
    else if stat == 1
      @.stop tab

auto_filler = new AutoFiller()

#
# Observer to detect pageload and change icons accordingly
