/// <reference path="../env/SessionStorage.ts" />
var econda;
(function (econda) {
    var tpm;
    (function (tpm) {
        var SessionStorage = econda.env.SessionStorage;
        /**
         * Internal helper class to detect if session was started and read session identifier.
         *
         * @class econda.tpm.Session
         */
        var Session = (function () {
            function Session() {
            }
            /**
             * True if this is the first page view of browser session
             *
             * @static
             * @returns {boolean}
             */
            Session.isFirstPageView = function () {
                return this._isFirstPageView;
            };
            /**
             * @static
             * @returns {any}
             */
            Session.getStartTimestamp = function () {
                return SessionStorage.getItem(Session.STORAGE_KEY);
            };
            /**
             * Initialize session. Will be called automatically.
             *
             * @static
             * @returns {boolean} session available
             */
            Session.init = function () {
                if (SessionStorage.isAvailable() == false) {
                    return false;
                }
                if (SessionStorage.getItem(Session.STORAGE_KEY) == null) {
                    this._isFirstPageView = true;
                    SessionStorage.setItem(Session.STORAGE_KEY, (new Date()).toISOString());
                    return true;
                }
                return false;
            };
            /**
             * Start new session
             * @returns {boolean} session available
             */
            Session.startNext = function () {
                SessionStorage.removeItem(Session.STORAGE_KEY);
                return this.init();
            };
            Session.STORAGE_KEY = 'ec_tpm_sessionStarted';
            /**
             * @property {Boolean} isFirstPageView
             * @static
             */
            Session._isFirstPageView = false;
            return Session;
        }());
        tpm.Session = Session;
        Session.init();
    })(tpm = econda.tpm || (econda.tpm = {}));
})(econda || (econda = {}));