import { useState } from "react" import type { SelectionPatternScore } from "../api/selection.types" import { patternCaseImageById } from "./pattern-case-assets" interface PatternCaseImageProps { score: SelectionPatternScore | null } export function PatternCaseImage({ score }: PatternCaseImageProps) { const [failedSource, setFailedSource] = useState(null) const matchedCase = score?.status === "failed" ? null : score?.case if (!matchedCase) return null const source = patternCaseImageById[matchedCase.id as keyof typeof patternCaseImageById] return (

最接近案例:{matchedCase.name}

{formatScore(score?.value)} 分
{!source || failedSource === source ? (

案例图片暂不可用。

) : ( {`${matchedCase.name} setFailedSource(source)} src={source} /> )}
) } function formatScore(value: number | null | undefined) { return value === null || value === undefined ? "—" : value.toFixed(2) }