"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Util = /** @class */ (function () {
    function Util() {
    }
    Util.copy = function (obj) {
        return JSON.parse(JSON.stringify(obj));
    };
    Util.deepAssign = function (target) {
        var sources = [];
        for (var _i = 1; _i < arguments.length; _i++) {
            sources[_i - 1] = arguments[_i];
        }
        if (!sources.length) {
            return target;
        }
        var source = sources.shift();
        if (source === undefined) {
            return target;
        }
        if (Util.isMergebleObject(target) && Util.isMergebleObject(source)) {
            Object.keys(source).forEach(function (key) {
                if (Util.isMergebleObject(source[key])) {
                    if (!target[key]) {
                        target[key] = {};
                    }
                    Util.deepAssign(target[key], source[key]);
                }
                else {
                    target[key] = source[key];
                }
            });
        }
        return Util.deepAssign.apply(Util, [target].concat(sources));
    };
    ;
    Util.isObject = function (item) {
        return item !== null && typeof item === 'object';
    };
    Util.isMergebleObject = function (item) {
        return Util.isObject(item) && !Array.isArray(item);
    };
    Util.castToType = function (o) {
        var value = o;
        if (Number(value) && value !== "true" && value !== "false") {
            value = Number(value);
        }
        if (value === "0") {
            value = 0;
        }
        if (value === "true") {
            value = true;
        }
        if (value === "false") {
            value = false;
        }
        return value;
    };
    ;
    /**
     * Returns the current date as seconds since midnight Jan 1, 1970.
     */
    Util.getTimeStamp = function (date) {
        if (date === void 0) { date = null; }
        if (date) {
            if (typeof date === 'string') {
                return Math.round(+new Date(date) / 1000);
            }
            else {
                return Math.round(+date / 1000);
            }
        }
        else {
            return Math.round(+new Date() / 1000);
        }
    };
    /**
     * Returns a UUID.
     */
    Util.getUUID = function () {
        var d = new Date().getTime();
        var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
            var r = (d + Math.random() * 16) % 16 | 0;
            d = Math.floor(d / 16);
            return (c === 'x' ? r : (r & 0x7 | 0x8)).toString(16);
        });
        return uuid;
    };
    /**
     * Checks if the application is running in a browser.
     */
    Util.isOnline = function () {
        if (typeof window !== 'undefined' && window.navigator.onLine) {
            return true;
        }
        else {
            return false;
        }
    };
    // /**
    //  * Returns the size of the viewport.
    //  */
    // static viewportSize() {
    //     let obj: any = {};
    //     if (typeof window !== 'undefined') {
    //         if (window.innerHeight) {
    //             obj.width = window.innerWidth;
    //             obj.height = window.innerHeight;
    //         } else {
    //             obj.width = document.documentElement.clientWidth;
    //             obj.height = document.documentElement.clientHeight;
    //         }
    //     }
    //     // todo: native + nodejs
    //     if (typeof window === 'undefined') { }
    //     return obj;
    // }
    /**
     * Checks if the application is running in a browser.
     */
    Util.isBrowser = function () {
        return typeof window !== 'undefined';
    };
    Util.copyToClipboard = function (str) {
        var el = document.createElement('textarea'); // Create a <textarea> element
        el.value = str; // Set its value to the string that you want copied
        el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof
        el.style.position = 'absolute';
        el.style.left = '-9999px'; // Move outside the screen to make it invisible
        document.body.appendChild(el); // Append the <textarea> element to the HTML document
        var selected = document.getSelection().rangeCount > 0 // Check if there is any content selected previously
            ? document.getSelection().getRangeAt(0) // Store selection if found
            : false; // Mark as false to know no selection existed before
        el.select(); // Select the <textarea> content
        document.execCommand('copy'); // Copy - only works as a result of a user action (e.g. click events)
        document.body.removeChild(el); // Remove the <textarea> element
        if (selected) { // If a selection existed before copying
            document.getSelection().removeAllRanges(); // Unselect everything on the HTML document
            document.getSelection().addRange(selected); // Restore the original selection
        }
    };
    return Util;
}());
exports.Util = Util;
//# sourceMappingURL=util.js.map