import { roundRobin } from "https://esm.town/v/thedavis/roundRobin";
export function whoNext(query, arg) {
const m = {
"help": () =>
"list/peek/rotate to view/peek/modify the schedule. add/remove with an argument also supported.",
"add": (arg) => {
roundRobin.push(arg);
return roundRobin.toString();
},
"list": () => roundRobin.toString(),
"peek": () =>
roundRobin.length === 0
? "Nobody in the round robin!"
: roundRobin[0],
"rotate": () => {
if (roundRobin.length == 0) {
return "Nobody in the round robin!";
}
else {
let shifted = roundRobin.shift();
roundRobin.push(shifted);
return shifted;
}
},
"remove": (arg) => {
const index = roundRobin.indexOf(arg);
if (index > -1) {
roundRobin.splice(index, 1);
}
},
"defer": (arg) => {
let deferred = roundRobin.shift();
let newNext = roundRobin.shift();
roundRobin.unshift(deferred);
roundRobin.unshift(newNext);
},
};
const v = m[query];
if (v) {
return v(arg);
}
else {
return `Unknown query "${query}", try 'help'.`;
}
}