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

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

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 < 2; i++) {
        let arrival = pids.arrivals().get(i);
        if (arrival != null) {
            let routeNumberSpace = "";
            if (arrival.routeNumber()) {
                routeNumberSpace = " ";
            }

            Text.create("Arrival route + destination")
            .text(TextUtil.cycleString(arrival.routeNumber()) + routeNumberSpace + TextUtil.cycleString(arrival.destination()))
            .color(0xFFFFFF)
            .pos(0, i*26+16)
            .scale(2)
            .stretchXY()
            .size(75, 100)
            .draw(ctx);

            if (TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" sec","s").replace(" mins","").replace(" min","") == "") {
                Text.create("Arrival time")
                .text("NOW")
                .color(0xFFFFFF)
                .pos(185, i*26+16)
                .rightAlign()
                .scale(2)
                .draw(ctx);
            } else {
                Text.create("Arrival time")
                .text(TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" sec","s").replace(" mins","").replace(" min",""))
                .color(0xFFFFFF)
                .pos(185, i*26+16)
                .rightAlign()
                .scale(2)
                .draw(ctx);
            }
        }
    }
}

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