// Game variants offered on New Game, and the Stage 15 gating of that choice by the // languages the sign-in service supports. Kept out of the .svelte screen so the // gating is unit-testable (the project's node-env Vitest layer). import type { MessageKey } from './i18n/index.svelte'; import type { Variant } from './model'; // VariantOption is a selectable game variant with its i18n label key. export interface VariantOption { id: Variant; label: MessageKey; } // ALL_VARIANTS lists every variant in display order. export const ALL_VARIANTS: VariantOption[] = [ { id: 'english', label: 'new.english' }, { id: 'russian_scrabble', label: 'new.russian' }, { id: 'erudit', label: 'new.erudit' }, ]; // VARIANT_LANGUAGE maps each variant to its game language. en -> English; // ru -> Russian + Эрудит. export const VARIANT_LANGUAGE: Record = { english: 'en', russian_scrabble: 'ru', erudit: 'ru' }; // availableVariants gates ALL_VARIANTS by the session's supported languages. An empty // or absent set is ungated (a web/legacy session without a declared set), returning // every variant. export function availableVariants(supportedLanguages: string[] | undefined): VariantOption[] { const langs = supportedLanguages ?? []; if (langs.length === 0) return ALL_VARIANTS; return ALL_VARIANTS.filter((v) => langs.includes(VARIANT_LANGUAGE[v.id])); }