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

    let arrival = pids.arrivals().get(0);
    if (arrival != null) {
        Text.create("Arrival route name")
        .text(`${TextUtil.getNonExtraParts(arrival.routeName())} No. ${arrival.routeNumber()}`)
        .color(oldLEDColors.yellow)
        .pos(93, 5.5)
        .centerAlign()
        .scale(2)
        .stretchXY()
        .size(90, 100)
        .draw(ctx);

        Text.create("Arrival destination")
        .text(`To ${TextUtil.cycleString(arrival.destination())}`)
        .color(oldLEDColors.yellow)
        .pos(93, 25.5)
        .centerAlign()
        .scale(2)
        .stretchXY()
        .size(90, 100)
        .draw(ctx);

        let arrivalTime = TextUtil.getNonCjkParts(PIDSUtil.getETAText(arrival.arrivalTime())).replace(" mins"," min");
        if (arrivalTime == "") {
            arrivalTime = "Status - Boarding";
        }

        Text.create("Arrival time")
        .text(arrivalTime)
        .color(oldLEDColors.yellow)
        .pos(93, 45.5)
        .centerAlign()
        .scale(2)
        .stretchXY()
        .size(90, 100)
        .draw(ctx);
    }
}

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