62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { Container, type SelectItem, SelectList, type SgrMouseEvent } from "@oh-my-pi/pi-tui";
|
|
import { getSelectListTheme } from "../../modes/theme/theme";
|
|
import { DynamicBorder } from "./dynamic-border";
|
|
import { routeSelectListMouseWithTopBorder } from "./select-list-mouse-routing";
|
|
|
|
/**
|
|
* Component that renders a queue mode selector with borders
|
|
*/
|
|
export class QueueModeSelectorComponent extends Container {
|
|
#selectList: SelectList;
|
|
|
|
constructor(
|
|
currentMode: "all" | "one-at-a-time",
|
|
onSelect: (mode: "all" | "one-at-a-time") => void,
|
|
onCancel: () => void,
|
|
) {
|
|
super();
|
|
|
|
const queueModes: SelectItem[] = [
|
|
{
|
|
value: "one-at-a-time",
|
|
label: "one-at-a-time",
|
|
description: "Process queued messages one by one (recommended)",
|
|
},
|
|
{ value: "all", label: "all", description: "Process all queued messages at once" },
|
|
];
|
|
|
|
// Add top border
|
|
this.addChild(new DynamicBorder());
|
|
|
|
// Create selector
|
|
this.#selectList = new SelectList(queueModes, 2, getSelectListTheme());
|
|
|
|
// Preselect current mode
|
|
const currentIndex = queueModes.findIndex(item => item.value === currentMode);
|
|
if (currentIndex !== -1) {
|
|
this.#selectList.setSelectedIndex(currentIndex);
|
|
}
|
|
|
|
this.#selectList.onSelect = item => {
|
|
onSelect(item.value as "all" | "one-at-a-time");
|
|
};
|
|
|
|
this.#selectList.onCancel = () => {
|
|
onCancel();
|
|
};
|
|
|
|
this.addChild(this.#selectList);
|
|
|
|
// Add bottom border
|
|
this.addChild(new DynamicBorder());
|
|
}
|
|
|
|
getSelectList(): SelectList {
|
|
return this.#selectList;
|
|
}
|
|
|
|
routeMouse(event: SgrMouseEvent, line: number, col: number): void {
|
|
routeSelectListMouseWithTopBorder(this.#selectList, event, line, col);
|
|
}
|
|
}
|