export function resolvePromptPreviewOptionValue<T extends { value: string }>(
  options: readonly T[],
  activePreviewOptionValue: string | null,
  selectedValues: string[],
) {
  const hasActivePreview = activePreviewOptionValue
    ? options.some((option) => option.value === activePreviewOptionValue)
    : false;

  if (hasActivePreview) {
    return activePreviewOptionValue;
  }

  return options.find((option) => selectedValues.includes(option.value))?.value ?? options[0]?.value ?? null;
}
