const player = mp.players.local;

export default function vehicleIndicators() {

    mp.keys.bind(0x64, true, function () {
        if (!player.vehicle) return;
        mp.events.callRemote("CLIENT:toggleLeftIndicator");
    });

    mp.keys.bind(0x66, true, function () {
        if (!player.vehicle) return;
        mp.events.callRemote("CLIENT:toggleRightIndicator");
    });

    mp.keys.bind(0x65, true, function () {
        if (!player.vehicle) return;
        mp.events.callRemote("CLIENT:toggleWarningIndicator");
    });

    mp.events.add("SERVER:setIndicatorStatus", (vehicle, left, right) => {
        var veh = mp.vehicles.atRemoteId(vehicle);

        veh.setIndicatorLights(0, right);
        veh.setIndicatorLights(1, left);
    });

    mp.events.add("entityStreamIn", entity => {
        if (entity === undefined || entity === null || !entity.isAVehicle()) return;

        var data = entity.getVariable("indicatorData");
        if (data) {
            entity.setIndicatorLights(0, data.Right);
            entity.setIndicatorLights(1, data.Left);
        }
    });
}