(function() {

    ready(function () {
        Nonstop.default.initialize({
            environment: window.environment,
            platform: 'web',
            cdnUrl: '../../dist/'
        });

        var userInput = {
            firstName: chance.first(),
            externalId: chance.guid(),
            email: chance.email()
        };

        Nonstop.default.login(userInput, true).then(function() {
            var pointsWidgetContainer = document.querySelectorAll('.points-widget-wrapper')[0];
            Nonstop.default.presentPointsWidget(pointsWidgetContainer);

            var noRightRound = document.querySelectorAll('.no-right-round')[0];
            Nonstop.default.presentPointsWidget(noRightRound, { isRightRounded: false });

            var noLeftRound = document.querySelectorAll('.no-left-round')[0];
            Nonstop.default.presentPointsWidget(noLeftRound, { isLeftRounded: false });

            var noDropdown = document.querySelectorAll('.no-message')[0];
            Nonstop.default.presentPointsWidget(noDropdown, { dropdownEnabled: false });
        });

        var pointsButton = document.querySelectorAll('.js-add-points')[0];
        pointsButton.addEventListener('click', function() {
            var watch1MinuteContentTask = {
                'contentId': 'VDKA0_52i1bahk',
                'task': 'watch-1-minute-of-content',
            };
            Nonstop.default.userPerformedTask(watch1MinuteContentTask);
        });

        var exceedLimit = document.querySelectorAll('.js-exceed-limit')[0];
        exceedLimit.addEventListener('click', function() {
            Nonstop.default.exceedPointsLimit();
        });

        document.addEventListener(Nonstop.default.Events.GoToNonstopHome, function() {
            alert('Go To Nonstop Home Event fired');
        });
    });

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

})();