"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useListInput = void 0;
const useKeypress_1 = require("./useKeypress");
const useListInput = function (value, values, { active, minus, plus, set, loop = true }) {
    (0, useKeypress_1.useKeypress)({ active }, (ch, key) => {
        // It's fine if the value doesn't exist inside the list
        const index = values.indexOf(value);
        switch (key.name) {
            case minus:
                {
                    const nextValueIndex = index - 1;
                    if (loop) {
                        set(values[(values.length + nextValueIndex) % values.length]);
                        return;
                    }
                    if (nextValueIndex < 0)
                        return;
                    set(values[nextValueIndex]);
                }
                break;
            case plus:
                {
                    const nextValueIndex = index + 1;
                    if (loop) {
                        set(values[nextValueIndex % values.length]);
                        return;
                    }
                    if (nextValueIndex >= values.length)
                        return;
                    set(values[nextValueIndex]);
                }
                break;
        }
    }, [values, value, plus, set, loop]);
};
exports.useListInput = useListInput;
