var EventLogUtil = {
    init: function (view) {
        z.dom.queryAll('.check-label').forEach(function (checkEle, index) {
            if (!checkEle.style.color) {
                z.dom.setStyle(checkEle, "color", z.util.color.defaults(index))
            }
        });
        var eventPre = z.dom.query(".log-pre");
        if (eventPre) {
            z.dom.event.on(eventPre, "contextmenu", function (evt) {
                evt.preventDefault();
                eventPre.innerHTML = "";
            });
        }
    },
    getNames: function (data) {//when type==="set" data is array
        if (data == null) {
            return null;
        }
        if (z.type.isArray(data)) {
            var names = [];
            data.forEach(function (d) {
                names.push(EventLogUtil.getDataName(d));
            });
            return names.join(",");
        }
        return EventLogUtil.getDataName(data);
    },
    getDataName: function (data) {
        if (!z.type.isData(data)) {
            return data;
        }
        var cls = data.getClassName();
        var name = data.get("name");
        if (name) {
            return name + "(" + cls + ")";
        }
        return cls + " ins";
    },
    logEvent: function (type, info) {
        var eventPre = z.dom.query(".log-pre");
        if (!eventPre) {
            return;
        }
        var typeCheck = z.dom.query("#" + type + "_check");
        if (z.dom.getValue(typeCheck) === false) {
            return;
        }
        var color = z.dom.getStyle(typeCheck.parentNode, "color");
        var label = "<label style='color:" + color + "'>";
        label += "<strong>event:</strong>" + type + "";
        if (info) {
            z.util.eachObject(info, function (p, v) {
                if (z.type.isData(v)) {
                    v = EventLogUtil.getNames(v)
                }
                if (z.type.isObject(v)) {
                    v = JSON.stringify(v);
                }
                label += "<br><strong>" + p + ":</strong>" + v;
            });
        }
        label += "</label><br><br>";
        var current = (new Date()).getTime();
        if (EventLogUtil.lastEventTime) {
            if (current - EventLogUtil.lastEventTime > 100) {
                label += "----------------------------<br>";
                EventLogUtil.lastEventTime = current;
            }
        } else {
            EventLogUtil.lastEventTime = current;
        }
        z.dom.setValue(eventPre, label + z.dom.getValue(eventPre));
        eventPre.scrollTop = 0;
    }
};
z.ready(function () {
    EventLogUtil.init();
});