"use strict";
class AndroidLogFilter {
    constructor($loggingLevels) {
        this.$loggingLevels = $loggingLevels;
    }
    filterData(data, logLevel) {
        let specifiedLogLevel = (logLevel || '').toUpperCase();
        if (specifiedLogLevel === this.$loggingLevels.info) {
            let log = this.getConsoleLogFromLine(data);
            if (log) {
                if (log.tag) {
                    return `${log.tag}: ${log.message}`;
                }
                else {
                    return log.message;
                }
            }
            return null;
        }
        return data;
    }
    getConsoleLogFromLine(lineText) {
        let acceptedTags = ["chromium", "Web Console", "JS"];
        let match = lineText.match(AndroidLogFilter.LINE_REGEX) || lineText.match(AndroidLogFilter.API_LEVEL_23_LINE_REGEX);
        if (match && acceptedTags.indexOf(match[1].trim()) !== -1) {
            return { tag: match[1].trim(), message: match[2] };
        }
        let matchingTag = _.some(acceptedTags, (tag) => { return lineText.indexOf(tag) !== -1; });
        return matchingTag ? { message: lineText } : null;
    }
}
AndroidLogFilter.LINE_REGEX = /.\/(.+?)\s*\(\s*\d+?\): (.*)/;
AndroidLogFilter.API_LEVEL_23_LINE_REGEX = /.+?\s+?(?:[A-Z]\s+?)([A-Za-z ]+?)\s*?\: (.*)/;
exports.AndroidLogFilter = AndroidLogFilter;
$injector.register("androidLogFilter", AndroidLogFilter);
