"use client";
import { useState } from "react";
const CUSTOM_OPTION = "__custom__";
type Props = {
value: string;
onChange: (next: string) => void;
defaultQueueKey: string;
existingQueues: string[];
actionLabel: string;
};
export function QueueControl({
value,
onChange,
defaultQueueKey,
existingQueues,
actionLabel,
}: Props) {
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState(value);
if (editing) {
return (
setDraft(e.target.value)}
aria-label={`custom queue for ${actionLabel}`}
autoFocus
placeholder="leave empty for immediate"
onKeyDown={(e) => {
if (e.key === "Enter") {
e.preventDefault();
onChange(draft.trim());
setEditing(false);
} else if (e.key === "Escape") {
e.preventDefault();
setEditing(false);
setDraft(value);
}
}}
className="w-44 font-mono px-2 py-1 rounded border border-border bg-card"
/>
);
}
// Compose options: blank (immediate) first, then default queue, current
// value, and any active queues, deduplicated.
const named = Array.from(
new Set(
[defaultQueueKey, value, ...existingQueues].filter((s) => s.length > 0),
),
).sort();
return (
);
}