import { Context } from "../context/context";
import { ConnectionState } from "../rtmt/rtmt";
import notyf from "./Notyf";

export default class Util {
    public static range(size: number) {
        var ans: number[] = [];
        for (let i = 0; i < size; i++) {
            ans.push(i);
        }
        return ans;
    }

    public static checkConnectionAndMaybeAlert(context: Context): boolean {
        if (context.rtmt.connectionState !== "connected") {
            notyf.error(context.texts.ConnectionLost);
            return true;
        }
        return false;
    }

    public static getTextByConnectionState(context: Context, connectionState: ConnectionState): string {
        const map: { [key: string]: string } = {
            connecting: context.texts.Connecting,
            connected: context.texts.Connected,
            error: context.texts.CannotConnect,
            closed: context.texts.ConnectingAgain,
            reconnecting: context.texts.ConnectingAgain,
        };
        return map[connectionState];
    }
}
