import type { DebugPublishMeta } from '../../utils/debugPublish'; import { inferGradeFromAge } from '../../utils/debugPublish'; import { FOCUS_WORKSHEET_DEFINITIONS } from '../../config/worksheets/focus'; export { FOCUS_WORKSHEET_DEFINITIONS }; type FocusWorksheetDefinitionItem = (typeof FOCUS_WORKSHEET_DEFINITIONS)[number]; const FOCUS_WORKSHEET_BY_ID = Object.fromEntries( FOCUS_WORKSHEET_DEFINITIONS.map((item) => [item.id, item]), ) as Record; function resolveFocusPublishId( routeId: string, selectedTypeId: string, mode?: string, ): string { if (selectedTypeId === 'grid-drawing') { return `grid-drawing-${mode || '3x3'}`; } if (routeId in FOCUS_WORKSHEET_BY_ID) { return routeId; } return selectedTypeId; } export function getPublishMetaByFocusState( routeId: string, selectedTypeId: string, mode?: string, ): DebugPublishMeta | null { const id = resolveFocusPublishId(routeId, selectedTypeId, mode); const item = FOCUS_WORKSHEET_BY_ID[id]; if (!item) return null; return { id: item.id, title: item.title, subtitle: item.subtitle, category: 'puzzle', subcategory: 'focus-draw', path: `/focusPages/focusDraw/focusDraw?id=${item.id}`, ageMin: item.ageMin, ageMax: item.ageMax, grade: inferGradeFromAge(item.ageMin, item.ageMax), difficulty: item.difficulty, previewImg: '', tags: [...item.tags], isNew: false, isHot: false, sortOrder: item.sortOrder, status: 'draft', }; }