import { memo } from 'react'; import { useTranslation } from 'react-i18next'; import type { TFunction } from 'i18next'; import type { SchoolMetadata } from '../../types'; import { POI_GROUP_COLORS } from '../../lib/consts'; import { getPoiIconUrl } from '../../lib/map-utils'; import { ts } from '../../i18n/server'; export interface PoiPopupCardData { name: string; category: string; icon_category?: string; group: string; emoji: string; school?: SchoolMetadata; } function getPoiGroupColor(group: string): [number, number, number] { const color = POI_GROUP_COLORS[group]; if (!color) { throw new Error(`Missing POI group color for '${group}'`); } return color; } /** Best-effort web URL from a free-text website field. GIAS stores some with * "http://", some without, and some as bare hostnames. */ function normalizeSchoolWebsiteUrl(raw: string): string | null { const trimmed = raw.trim(); if (!trimmed) return null; if (/^https?:\/\//i.test(trimmed)) return trimmed; if (/^[\w.-]+\.[a-z]{2,}/i.test(trimmed)) return `http://${trimmed}`; return null; } function renderSchoolMetadata(school: SchoolMetadata, t: TFunction) { // First line collects the headline classification (phase, type, religious // character) so the popup is scannable even when most fields are absent. const headline: string[] = []; if (school.phase) headline.push(school.phase); if (school.type) headline.push(school.type); const pupilsLine = school.pupils !== undefined && school.capacity !== undefined ? `${school.pupils.toLocaleString()} / ${school.capacity.toLocaleString()} ${t('poiPopup.school.pupils')}` : school.pupils !== undefined ? `${school.pupils.toLocaleString()} ${t('poiPopup.school.pupils')}` : school.capacity !== undefined ? `${t('poiPopup.school.capacity')} ${school.capacity.toLocaleString()}` : null; const websiteUrl = school.website ? normalizeSchoolWebsiteUrl(school.website) : null; return (