 # See: http://cl.ly/image/3q040w1J2I2y/o
 #
 
-{ track } = analytics = require '../../../lib/analytics.coffee'
 Cookies = require 'cookies-js'
 mediator = require '../../../lib/mediator.coffee'
 
-MODE = Cookies.get('save-controls') or analytics.getProperty('ab:save:controls')
+MODE = Cookies.get('save-controls')
 
 # Funnel 1 (NUX Onboarding modal to new set made)
 # ------------------------------------------------------------------------------

    return if ($(e.target).closest(
                 '.favorites2-collection-list-container'
              ).length > 0 and not $(e.target).hasClass('.modal-close'))
    track.funnel 'Set Management: Open menu - dismiss'

# Hover on work
$(document).on 'mouseenter', '.artwork-item', ->
  hoverTimeout = setTimeout ->
    hoverTimeout = null
    track.funnel 'Set Management: Hover on work'
  , 300

# Click remove
$(document).on 'click', '.artwork-item-remove', ->
  clickedSaveControl = true
  track.click 'Set Management: Click remove'

# Click favicon
$(document).on 'click', '.overlay-button-save, .circle-icon-button-save', (e) ->
  clickedSaveControl = true
  track.funnel 'Set Management: Click favicon'
  if $(e.target).closest('.save-controls-one-btn-container').length
    listenForMenuDismiss()
  if $(e.target).closest('.save-controls-two-btn-container').length
    track.funnel 'Set Management: Successful save'

# Click set stack
$(document).on 'click', ('.save-controls-two-btn-add-to-collection, ' +
                         '.circle-icon-button-add'), ->
  clickedSaveControl = true
  openedMenu = true
  track.funnel 'Set Management: Click set stack'
  listenForMenuDismiss()

# Dismiss
$(document).on 'mouseleave', '.artwork-item', (e) ->
  return clearTimeout(hoverTimeout) if hoverTimeout
  unless clickedSaveControl
    track.funnel 'Set Management: Hover on work - dismiss'
  clickedSaveControl = false

# Work saved to My Favs
$(document).on 'click', ('.save-controls-drop-down-container ' +
                         '.overlay-button-save, .circle-icon-button-save'), ->
  return unless MODE is 'drop down'
  track.funnel 'Set Management: Work Saved to My Favs'
  track.funnel 'Set Management: Successful save'
  listenForMenuDismiss()

# Added to set X

# Remove via X in corner
$(document).on 'click', ('.favorites2-edit-modal-delete-confirm'), (e) ->
  return unless $(e.target).text() is 'Remove work'
  analytics.track 'Set Management: Remove from set', inline: false

# Delete set
$(document).on 'click', ('.favorites2-edit-modal-init + ' +
                         '.favorites2-edit-modal-delete-container' +
                         'favorites2-edit-modal-delete-confirm'), ->
  analytics.track 'Set Management: Delete set'

# Privacy switch
$(document).on 'click', '.favorites2-toggle-public', ->
  analytics.track 'Set Management: Make private'
$(document).on 'click', '.favorites2-toggle-private', ->
  analytics.track 'Set Management: Make public'

# Slideshow
$(document).on 'click', '#user-profile-collection-right-slideshow', ->
  analytics.track 'Set Management: Slideshow'

# Share set
$(document).on 'click', '#user-profile-collection-right-share', ->
  analytics.track 'Set Management: Share set'
