window.amplitude = {
    Identify: function () {
        var identify = {
            values: {
                set: {},
                add: {}
            },
            set: function (key, value) {
                identify.values.set[key] = value;
                return identify;
            },
            add: function (key, value) {
                identify.values.add[key] = value;
                return identify;
            },
            setOnce: function (key, value) { identify.set(key, value); }
        }
        return identify;
    },
    Revenue: function () {
        var revenue = {
            productId: null,
            price: null,
            quantity: null,

            setProductId: function (productId) {
                revenue.productId = productId;
                return revenue;
            },
            setPrice: function (price) {
                revenue.price = price;
                return revenue;
            },
            setQuantity: function (quantity) {
                revenue.quantity = quantity;
                return revenue;
            }
        }
        return revenue;
    },
    getInstance: function () {
        return amplitude._instance;
    },
    event: null,
    identify: null,
    revenue: null,
    userId: null,

    _instance: {
        identify: function (identify) {
            console.log('Amplitude Logged User Data:');
            console.log(JSON.stringify(identify.values));
            amplitude.identify = identify.values;
        },
        logRevenueV2: function (revenue) {
            amplitude.revenue = revenue;
        },
        logEvent: function (eventName, eventProperties) {
            console.log('Amplitude Tracked Event: ' + eventName);
            console.log('Amplitude with data:');
            console.log(JSON.stringify(eventProperties));
            amplitude.event = {
                eventName: eventName,
                eventProperties: eventProperties
            };
        },
        setUserId: function(userId) {
            amplitude.userId = userId;
        }
    }
};

(function() {

    ready(function() {
        var currentEnv = sessionStorage.getItem('environment');
        if(!currentEnv) {
            currentEnv = 'staging';
        }

        var environmentDropdown = document.getElementById('Environment');
        environmentDropdown.value = currentEnv;
        window.environment = currentEnv;

        environmentDropdown.addEventListener('change', function(e) {
            sessionStorage.setItem('environment', environmentDropdown.value);
            window.location.reload();
        });
    });

    function ready(fn) {
        if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
            fn();
        } else {
            document.addEventListener('DOMContentLoaded', fn);
        }
    }

})();