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 < 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(oldLEDColors.yellow)
            .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(oldLEDColors.yellow)
                .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(oldLEDColors.yellow)
                .pos(185, i*26+16)
                .rightAlign()
                .scale(2)
                .draw(ctx);
            }
        }
    }
}

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