import React, { useId, useMemo, useState } from "react"; import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import { Box, Button, Chip, Paper, Stack, Typography } from "@mui/material"; import { CvTheme, getVisibleCvThemes } from "../cvBuilder"; import { useI18n } from "../i18n/I18nProvider"; import CvTemplateThumbnail from "./CvTemplateThumbnail"; type Props = { themes: CvTheme[]; selectedId: string; onSelect: (theme: CvTheme) => void; previewHeight?: number; showDescriptions?: boolean; }; export default function CvTemplateGallery({ themes, selectedId, onSelect, previewHeight = 170, showDescriptions = true }: Props) { const { t } = useI18n(); const id = useId(); const [atsOnly, setAtsOnly] = useState(true); const visibleThemes = useMemo(() => getVisibleCvThemes(themes, atsOnly, selectedId), [atsOnly, selectedId, themes]); return ( {atsOnly && {t("cvEditorAtsTemplateHelp")}} {visibleThemes.map((theme) => { const active = theme.id === selectedId; const locked = theme.available === false; return ( { if (!locked) onSelect(theme); }} onKeyDown={(event) => { if (!locked && (event.key === "Enter" || event.key === " ")) { event.preventDefault(); onSelect(theme); } }} sx={{ p: 1, cursor: locked ? "not-allowed" : "pointer", position: "relative", borderColor: active ? "primary.main" : "divider", borderWidth: active ? 2 : 1, "&:hover": locked ? undefined : { borderColor: "primary.main" } }}> {active && } {theme.name} {theme.category} {showDescriptions && {theme.description}} {theme.atsFriendly && } {theme.requiresPro && } {theme.swatches.slice(0, 3).map((colour, index) => )} ); })} ); }