var log = document.getElementById('log');

/* 接收 C 发来的消息 — eduwin 由 C 端自动注入 */
eduwin.on_message(function(msg) {
    log.textContent = JSON.stringify(msg, null, 2) + '\n\n' + log.textContent;
});

function sayHello() {
    eduwin.call('hello', { name: 'eduwin' }, function(r) {
        log.textContent = '[回应] ' + r.reply + '\n\n' + log.textContent;
    });
}

function callTime() {
    eduwin.call('get_time', null, function(r) {
        log.textContent = '[时间] ' + r.time + '\n\n' + log.textContent;
    });
}

function callAdd() {
    var a = parseInt(document.getElementById('param_a').value) || 0;
    var b = parseInt(document.getElementById('param_b').value) || 0;
    eduwin.call('add_numbers', { a: a, b: b }, function(r) {
        log.textContent = '[加法] ' + a + ' + ' + b + ' = ' + r.result + '\n\n' + log.textContent;
    });
}
