 _ = require 'underscore'
 Backbone = require 'backbone'
-Cookies = require 'cookies-js'
-sd = require('sharify').data
+{ CURRENT_USER, NODE_ENV } = require('sharify').data
 { getProperty, setProperty, unsetProperty, setDimension } = require '../../lib/analytics.coffee'
+IS_TEST_ENV = not _.contains(['production', 'staging', 'development'], NODE_ENV)
 
 module.exports = class SplitTest
   constructor: ({ @key, @outcomes, @edge, @dimension }) ->

  _key: ->
    "split_test--#{@key}"

  set: (outcome) ->
    Cookies.set @_key(), outcome
    unsetProperty @_key() # Force unset
    setProperty _.tap({}, (hsh) => hsh[@_key()] = outcome)
    setDimension @dimension, outcome if @dimension?
    outcome

  get: ->
    getProperty(@_key()) or Cookies.get(@_key())

  unset: ->
    Cookies.expire @_key()
    unsetProperty @_key()
    location.reload()


    "is-splittest-#{@key}--#{@outcome()}"

  admin: ->
    CURRENT_USER?.type is 'Admin'

  toss: ->
    _.sample _.flatten _.map @outcomes, (probability, outcome) ->
