package dev.photosync.mcapi;

/**
 * The GLFW key and modifier codes the UI reacts to.
 *
 * <p>They are named here rather than read from LWJGL because {@code :shared:ui}
 * deliberately has no LWJGL on its classpath, and because {@code key == 259} at
 * a call site is unreadable in a way {@code key == Keys.BACKSPACE} is not. The
 * numbers are fixed by GLFW's ABI and have not changed in the library's history.
 */
public final class Keys {

    public static final int ESCAPE = 256;
    public static final int ENTER = 257;
    public static final int TAB = 258;
    public static final int BACKSPACE = 259;
    public static final int DELETE = 261;
    public static final int RIGHT = 262;
    public static final int LEFT = 263;
    public static final int DOWN = 264;
    public static final int UP = 265;
    public static final int PAGE_UP = 266;
    public static final int PAGE_DOWN = 267;
    public static final int HOME = 268;
    public static final int END = 269;
    public static final int KEYPAD_ENTER = 335;

    public static final int A = 65;
    public static final int C = 67;
    public static final int V = 86;
    public static final int X = 88;

    public static final int MOD_SHIFT = 0x1;
    public static final int MOD_CONTROL = 0x2;
    public static final int MOD_ALT = 0x4;
    public static final int MOD_SUPER = 0x8;

    private Keys() {
    }

    /**
     * Whether the copy/paste modifier is held: Control everywhere, and Command
     * on macOS, where GLFW reports it as Super.
     */
    public static boolean shortcut(int modifiers) {
        return (modifiers & (MOD_CONTROL | MOD_SUPER)) != 0;
    }

    public static boolean shift(int modifiers) {
        return (modifiers & MOD_SHIFT) != 0;
    }

    public static boolean confirms(int key) {
        return key == ENTER || key == KEYPAD_ENTER;
    }
}
