import 'object-defineproperty-ie8';
import './polyfill_expand'
import track from '@firesoon/log-sdk';
import "./styles/global.less";

$.support.cors = true

window._console = window.console;
window.console = (function (orgConsole) {
    function getConsoleFn(name) {
        return function actionConsole() {
            if (typeof (orgConsole) !== "object") return;
            if (typeof (orgConsole[name]) !== "function") return;
            return orgConsole[name].apply(orgConsole, Array.prototype.slice.call(arguments));
        };
    }
    return {
        log: getConsoleFn("log"),
        debug: getConsoleFn("debug"),
        info: getConsoleFn("info"),
        warn: getConsoleFn("warn"),
        exception: getConsoleFn("exception"),
        assert: getConsoleFn("assert"),
        dir: getConsoleFn("dir"),
        dirxml: getConsoleFn("dirxml"),
        trace: getConsoleFn("trace"),
        group: getConsoleFn("group"),
        groupCollapsed: getConsoleFn("groupCollapsed"),
        groupEnd: getConsoleFn("groupEnd"),
        profile: getConsoleFn("profile"),
        profileEnd: getConsoleFn("profileEnd"),
        count: getConsoleFn("count"),
        clear: getConsoleFn("clear"),
        time: getConsoleFn("time"),
        timeEnd: getConsoleFn("timeEnd"),
        timeStamp: getConsoleFn("timeStamp"),
        table: getConsoleFn("table"),
        error: getConsoleFn("error"),
        memory: getConsoleFn("memory"),
        markTimeline: getConsoleFn("markTimeline"),
        timeline: getConsoleFn("timeline"),
        timelineEnd: getConsoleFn("timelineEnd")
    };
}(window._console));

// 埋点
$(function () {
    const autoClickHandle = (e) => {
        const LogData = track.getLogData(e);
        const now = new Date().getTime();
        const userId = sessionStorage.getItem('operator_his');
    
        if (LogData) {
            const logs = {
                ...LogData,
                eventType: 'click',
                hospitalCode: sessionStorage.getItem('hosCode'),
                stamp: now,
                appVersion: '5.1.0',
                appCode: 'drg_thd_fl',
                userId,
            };
    
            ajaxPost(api.addLog, logs);
        }
    };
    track.listener.on(document.body, 'click', autoClickHandle);
});
