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);

    let arrival = pids.arrivals().get(0);
    if (arrival != null) {
        Text.create("Arrival route + destination")
        .text(TextUtil.cycleString(arrival.destination()))
        .color(0xFF0000)
        .pos(2, 6)
        .scale(2)
        .stretchXY()
        .size(65, 100)
        .draw(ctx);

        Text.create("Arrival car count")
        .text(`${arrival.carCount()}-CAR`)
        .color(0xFF0000)
        .pos(3, 24)
        .scale(1.3)
        .draw(ctx);

        if (TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" sec"," SEC").replace(" mins"," MIN").replace(" min","") == "") {
            Text.create("Arrival time")
            .text("0 MIN")
            .color(0xFF0000)
            .pos(183, 7)
            .rightAlign()
            .scale(1.3)
            .draw(ctx);
        } else {
            Text.create("Arrival time")
            .text(TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" sec"," SEC").replace(" mins"," MIN").replace(" min"," MIN"))
            .color(0xFF0000)
            .pos(183, 7)
            .rightAlign()
            .scale(1.3)
            .draw(ctx);
        }
    }
}

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