import type { ScentNotesBreakdownPayload } from '@homaroma/types'; import { useTranslation } from 'react-i18next'; import { getLocalizedField } from '../utils/localization'; interface DynamicScentNotesBreakdownProps { payload: ScentNotesBreakdownPayload; } export default function DynamicScentNotesBreakdown({ payload }: DynamicScentNotesBreakdownProps) { const { i18n } = useTranslation(); const lang = i18n.language; const title = getLocalizedField(payload.title, lang); const description = getLocalizedField(payload.description, lang); const notes = (value: ScentNotesBreakdownPayload['topNotes'] | ScentNotesBreakdownPayload['middleNotes'] | ScentNotesBreakdownPayload['baseNotes']) => Array.isArray(value) ? value.map((item) => getLocalizedField(item, lang)).filter(Boolean).join(', ') : getLocalizedField(value, lang); const labels = { th: { top: 'Top Notes', heart: 'Heart Notes', base: 'Base Notes' }, en: { top: 'Top Notes', heart: 'Heart Notes', base: 'Base Notes' }, ja: { top: 'トップノート', heart: 'ハートノート', base: 'ベースノート' }, zh: { top: '前调', heart: '中调', base: '后调' }, vi: { top: 'Hương đầu', heart: 'Hương giữa', base: 'Hương cuối' }, ko: { top: '탑 노트', heart: '미들 노트', base: '베이스 노트' } } as const; const labelSet = labels[lang as keyof typeof labels] ?? labels.en; const topNotes = notes(payload.topNotes); const heartNotes = notes(payload.middleNotes); const baseNotes = notes(payload.baseNotes); return (

{title || 'Scent Notes'}

{description && (

{description}

)}

{labelSet.top}

{topNotes || 'The initial, lighter smells of the fragrance.'}

{labelSet.heart}

{heartNotes || 'The core of the fragrance, emerging just after the top notes.'}

{labelSet.base}

{baseNotes || 'The deepest, richest scents that linger the longest.'}

); }