import {DomOutput} from "./lib/DomIO.js";
import {Lecture} from "./lib/Lecture.js";

const OUTPUT_ELEMENT_ID = "text-output";
let terminal = new DomOutput(OUTPUT_ELEMENT_ID);

document.addEventListener("DOMContentLoaded",() =>{
    document.getElementById("run").addEventListener("click", main);
});

/** JSON-Version */
function main() {
    // Object creation
    let lectures = [
        new Lecture("Informatik 1",     5, 4),
        new Lecture("Programmierung 1", 8, 5),
        new Lecture("JavaScript",       5, 4)
    ];
    let effortOfWeek = lectures.reduce( (acc, l) => l.effortPerWeek(15) + acc, 0);
    console.log(effortOfWeek);

    // Prototype
    let javascript = new Lecture("test", 8, 5);
    console.log(javascript.hasOwnProperty("effortPerWeek")); // false
    Lecture.prototype.effortPerWeek = function(week) {
        return 0;
    }
    console.log(javascript.effortPerWeek(15)); // → 0
    // setter
    javascript.sws = 6;
    console.log(javascript.sws);
    // for-in
    for(let key in javascript) {
        console.log(key);
    }
    // for-of
    for(let key of javascript) {
        console.log(key);
    }
}