namespace uniflashs {

    class Logger {

        static $inject = [];
        public printToConsole: boolean = false;

        private logObj: Array<string> = [];

        constructor() { }

        clean() {
            this.logObj = [];
        }

        log(arg: string) {
            this.logObj.push(arg);
        }

        private getLogObjStr(): string {
            let ret = '';
            _.each(this.logObj, (line) => {
                ret += line + '\n';
            });
            return ret;
        }

        save() {
            function isSafari() {
                return 'safari' === TICloudAgent.getBrowser();
            }

            let logObjStr = this.getLogObjStr();

            if (isSafari()) {
                let base64data = btoa(logObjStr);
                window.location.href = 'data:text/plain;charset=utf-8;base64,' + base64data;
            } else {
                let textFileAsBlob = new Blob([logObjStr], { type: 'text/plain;charset=utf-8' });
                saveAs(textFileAsBlob, 'uniflash_gui_debug_log');
            }
        }

    }

    angular.module('uniflash').service('ufLogger', Logger);
}