include(Resources.id("jsblock:scripts/pids_util.js"));
var eta;

function create(ctx, state, pids) {
    print("Hello World ^^");
}

const oldLEDColors = {
    red: 0xFF0000,
    yellow: 0xFCA103,
    green: 0xA9D130
};

function render(ctx, state, pids) {
    Texture.create("background")
    .texture("jsblock:textures/led_bg.png")
    .size(pids.width, pids.height)
    .draw(ctx);

    for (let i = 0; i < 4; i++) {
        let arrival = pids.arrivals().get(i);
        if (arrival != null) {
            Text.create("Arrival route")
            .text(TextUtil.cycleString(arrival.routeNumber()))
            .color(oldLEDColors.yellow)
            .pos(0, i*15.5+4.5)
            .scale(1.25)
            .draw(ctx);

            Text.create("Arrival destination")
            .text(TextUtil.cycleString(arrival.destination()))
            .color(oldLEDColors.yellow)
            .pos(28, i*15.5+4.5)
            .scale(1.25)
            .stretchXY()
            .size(95, 100)
            .draw(ctx);

            if (TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" sec","s").replace(" mins","m").replace(" min","m") == "") {
                Text.create("Arrival time")
                .text("Due")
                .color(oldLEDColors.yellow)
                .pos(185, i*15.5+4.5)
                .rightAlign()
                .scale(1.25)
                .draw(ctx);
            } else {
                Text.create("Arrival time")
                .text(TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" sec","s").replace(" mins","m").replace(" min","m"))
                .color(oldLEDColors.yellow)
                .pos(185, i*15.5+4.5)
                .rightAlign()
                .scale(1.25)
                .draw(ctx);
            }
        }
    }
}

function dispose(ctx, state, pids) {
    print("Goodbye World ^^;");
}