import { getCountryFromIso, getLanguageFromIso, } from '../../data/CountriesAndLanguages'; interface RulesSummaryArgs { level: number; countries: string[]; languages: string[]; allowedCount: number; blockedCount: number; } // Up to two names in full, then "+N more" — the sentence must stay one line // of state-of-play, not a list. function listNames( isos: string[], toName: ( iso: string ) => string ) { const names = isos.map( ( iso ) => toName( iso ) || iso ); if ( names.length <= 2 ) { return names.join( ' and ' ); } return `${ names[ 0 ] }, ${ names[ 1 ] } +${ names.length - 2 } more`; } // The protection levels, by the names the cloud gives them. The level is // chosen in the cloud; it is named here because it is part of what is in // effect on this site. const levelNames = [ 'Light', 'Standard', 'Maximum' ]; // One sentence summarising the rules as currently in effect — names and // counts only, never how the rules decide, and no control of any kind. export default function RulesSummary( { level, countries, languages, allowedCount, blockedCount, }: RulesSummaryArgs ) { const from = countries.length ? `from ${ listNames( countries, getCountryFromIso ) }` : ''; const inLang = languages.length ? `in ${ listNames( languages, getLanguageFromIso ) }` : ''; let location = ''; if ( from && inLang ) { location = `sign-ins accepted ${ from }, ${ inLang }`; } else if ( from || inLang ) { location = `sign-ins accepted ${ from || inLang }`; } const lists: string[] = []; if ( allowedCount > 0 ) { lists.push( `${ allowedCount } ${ 1 === allowedCount ? 'address' : 'addresses' } always allowed` ); } if ( blockedCount > 0 ) { lists.push( `${ blockedCount } blocked` ); } const parts = [ `${ levelNames[ level ] ?? levelNames[ 0 ] } protection`, location, lists.join( ', ' ), ].filter( Boolean ); const summary = `Currently: ${ parts.join( '; ' ) }.`; return
{ summary }
; }