2026-05-07 03:40:29 +03:30
|
|
|
'use client';
|
|
|
|
|
|
2026-08-19 23:59:37 +03:30
|
|
|
import { useId, useState, type CSSProperties, type ReactNode } from 'react';
|
2026-06-20 14:51:43 +03:30
|
|
|
import { useTranslations } from 'next-intl';
|
2026-08-19 23:59:37 +03:30
|
|
|
import { Info } from 'lucide-react';
|
|
|
|
|
import { Button } from '@/components/ui/shared/Button';
|
|
|
|
|
import { DialogCloseButton } from '@/components/ui/shared/DialogCloseButton';
|
|
|
|
|
import {
|
|
|
|
|
ResponsiveDialogOverlay,
|
|
|
|
|
ResponsiveDialogPanel,
|
|
|
|
|
} from '@/components/ui/shared/ResponsiveDialog';
|
2026-05-07 03:40:29 +03:30
|
|
|
import { FDI_LOWER_LEFT_TO_RIGHT, FDI_UPPER_LEFT_TO_RIGHT, getToothShapeKind } from '@/components/treatment/fdiToothMeta';
|
2026-08-19 00:06:21 +03:30
|
|
|
import {
|
|
|
|
|
getToothColumnWidthRem,
|
|
|
|
|
getToothGlyphWidthRem,
|
|
|
|
|
} from '@/components/treatment/fdiToothScale';
|
|
|
|
|
import { getRealisticToothAsset } from '@/components/treatment/realisticToothAssets';
|
|
|
|
|
import { toothEdgeKey } from '@/components/treatment/toothSelectionGroups';
|
2026-05-07 03:46:18 +03:30
|
|
|
import { ToothGlyph } from '@/components/ui/treatment/ToothGlyph';
|
2026-05-07 03:40:29 +03:30
|
|
|
import type { FdiToothId } from '@/types/treatment';
|
|
|
|
|
|
2026-05-08 03:58:53 +03:30
|
|
|
const TOOTH_NUMBER_GAP = 'mt-1';
|
2026-08-19 00:06:21 +03:30
|
|
|
/** Extra crown↔number space for realistic SVGs (outside arch transform so it is not cancelled). */
|
|
|
|
|
const REALISTIC_NUMBER_GAP = '2mm';
|
|
|
|
|
/** Tight interproximal gap between tooth columns. */
|
|
|
|
|
const TOOTH_GAP = 'gap-x-px';
|
2026-08-22 17:49:38 +03:30
|
|
|
/**
|
|
|
|
|
* Centers a mark on the inline-end edge of a tooth column (between this tooth
|
|
|
|
|
* and the next in flex order). Logical `end` + 0-width flex stays correct in LTR and RTL.
|
|
|
|
|
*/
|
|
|
|
|
const EDGE_MARK_ANCHOR =
|
|
|
|
|
'absolute inset-y-0 end-0 z-10 w-0 flex items-center justify-center';
|
2026-05-08 03:58:53 +03:30
|
|
|
|
2026-05-07 03:40:29 +03:30
|
|
|
function quadrantMirrored(fdi: FdiToothId): boolean {
|
|
|
|
|
const q = fdi[0];
|
|
|
|
|
return q === '2' || q === '3';
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-19 00:06:21 +03:30
|
|
|
/** Cartoon glyph height factor vs width (realistic assets use aspect ratio from viewBox). */
|
|
|
|
|
function cartoonHeightRem(fdi: FdiToothId, widthRem: number): number {
|
|
|
|
|
const kind = getToothShapeKind(fdi);
|
|
|
|
|
const factor = kind === 'canine' ? 2.85 : kind === 'molar' ? 2.45 : 2.65;
|
|
|
|
|
return Number((widthRem * factor).toFixed(3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toothSize(fdi: FdiToothId): {
|
|
|
|
|
columnWidthRem: number;
|
|
|
|
|
glyphWidthRem: number;
|
|
|
|
|
glyphHeightRem: number | 'auto';
|
|
|
|
|
} {
|
|
|
|
|
const glyphWidthRem = getToothGlyphWidthRem(fdi);
|
|
|
|
|
const columnWidthRem = getToothColumnWidthRem(fdi);
|
|
|
|
|
const realistic = Boolean(getRealisticToothAsset(fdi));
|
|
|
|
|
return {
|
|
|
|
|
columnWidthRem,
|
|
|
|
|
glyphWidthRem,
|
|
|
|
|
glyphHeightRem: realistic ? 'auto' : cartoonHeightRem(fdi, glyphWidthRem),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-19 23:59:37 +03:30
|
|
|
function ToothNumber({
|
|
|
|
|
fdi,
|
|
|
|
|
selected,
|
|
|
|
|
widthRem,
|
|
|
|
|
colorClass,
|
|
|
|
|
style,
|
|
|
|
|
interactive,
|
|
|
|
|
disabled,
|
|
|
|
|
onActivate,
|
|
|
|
|
}: {
|
|
|
|
|
fdi: FdiToothId;
|
|
|
|
|
selected: boolean;
|
|
|
|
|
widthRem: number;
|
|
|
|
|
colorClass: string;
|
|
|
|
|
style?: CSSProperties;
|
|
|
|
|
interactive: boolean;
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
onActivate: (shiftKey: boolean) => void;
|
|
|
|
|
}) {
|
|
|
|
|
const className = `text-[10px] tabular-nums text-center leading-none ${colorClass}`;
|
|
|
|
|
const boxStyle: CSSProperties = { width: `${widthRem}rem`, ...style };
|
|
|
|
|
|
|
|
|
|
if (!interactive) {
|
|
|
|
|
return (
|
|
|
|
|
<span className={className} style={boxStyle}>
|
|
|
|
|
{fdi}
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
disabled={disabled}
|
|
|
|
|
data-fdi={fdi}
|
|
|
|
|
onMouseDown={(e) => {
|
|
|
|
|
if (e.shiftKey) e.preventDefault();
|
|
|
|
|
}}
|
|
|
|
|
onPointerDown={(e) => {
|
|
|
|
|
if (e.button !== 0) return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onActivate(e.shiftKey);
|
|
|
|
|
}}
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
onActivate(e.shiftKey);
|
|
|
|
|
}}
|
|
|
|
|
aria-pressed={selected}
|
|
|
|
|
className={`${className} bg-transparent select-none touch-manipulation focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50 ${
|
|
|
|
|
disabled ? 'cursor-not-allowed' : 'cursor-pointer'
|
|
|
|
|
}`}
|
|
|
|
|
style={boxStyle}
|
|
|
|
|
>
|
|
|
|
|
{fdi}
|
|
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-07 03:40:29 +03:30
|
|
|
interface FdiToothChartProps {
|
|
|
|
|
selected: ReadonlySet<FdiToothId>;
|
2026-08-19 00:06:21 +03:30
|
|
|
/**
|
|
|
|
|
* Legacy / read-only: teeth in a connected bridge.
|
|
|
|
|
* When `linkedEdges` is omitted, filled marks are shown between adjacent
|
|
|
|
|
* selected teeth that both appear in this set.
|
|
|
|
|
*/
|
2026-07-17 00:39:32 +03:30
|
|
|
connectedTeeth?: ReadonlySet<FdiToothId>;
|
2026-08-19 00:06:21 +03:30
|
|
|
/** Filled connection edges (`toothEdgeKey(a,b)`). Preferred over `connectedTeeth` for edit mode. */
|
|
|
|
|
linkedEdges?: ReadonlySet<string>;
|
2026-07-18 00:02:40 +03:30
|
|
|
onToggle?: (fdi: FdiToothId, event: { shiftKey: boolean }) => void;
|
2026-08-19 00:06:21 +03:30
|
|
|
/** Toggle connect/disconnect for an adjacent selected pair. */
|
|
|
|
|
onToggleLink?: (a: FdiToothId, b: FdiToothId) => void;
|
2026-05-07 03:40:29 +03:30
|
|
|
disabled?: boolean;
|
2026-07-07 18:43:10 +03:30
|
|
|
/** Non-interactive display (Cases / connection history). */
|
|
|
|
|
readOnly?: boolean;
|
|
|
|
|
/** Visual scale via CSS zoom (0.5 = half size). */
|
|
|
|
|
scale?: number;
|
|
|
|
|
/** Per-tooth accent color for selected glow (prosthesis / treatment-type palettes). */
|
|
|
|
|
toothColors?: Partial<Record<FdiToothId, string>>;
|
|
|
|
|
/** Extra control rendered in the chart header (e.g. whole-plan checkbox). */
|
|
|
|
|
headerControl?: ReactNode;
|
|
|
|
|
/** Compact card for embedded case detail panels. */
|
|
|
|
|
compact?: boolean;
|
2026-08-19 23:59:37 +03:30
|
|
|
/** Nested in the treatment editor — no extra card chrome. */
|
|
|
|
|
embedded?: boolean;
|
2026-07-07 18:43:10 +03:30
|
|
|
className?: string;
|
2026-05-07 03:40:29 +03:30
|
|
|
}
|
|
|
|
|
|
2026-08-19 00:06:21 +03:30
|
|
|
/**
|
|
|
|
|
* Distal tip for arch look — gentler than pre-SVG angles so realistic glyphs stay readable.
|
|
|
|
|
* Positive rotate = clockwise.
|
|
|
|
|
*/
|
|
|
|
|
const TOOTH_TWEAKS: Partial<Record<FdiToothId, { offset: number; rotate: number }>> = {
|
|
|
|
|
'18': { offset: 5, rotate: -7 },
|
|
|
|
|
'17': { offset: 6, rotate: -5 },
|
|
|
|
|
'16': { offset: 6, rotate: -3.5 },
|
|
|
|
|
'15': { offset: 6, rotate: -2 },
|
|
|
|
|
'14': { offset: 5, rotate: -1 },
|
|
|
|
|
'13': { offset: 5.5, rotate: -0.5 },
|
|
|
|
|
'12': { offset: 4, rotate: -0.25 },
|
|
|
|
|
'11': { offset: 5, rotate: 0 },
|
|
|
|
|
'21': { offset: 5, rotate: 0 },
|
|
|
|
|
'22': { offset: 4, rotate: 0.25 },
|
|
|
|
|
'23': { offset: 5.5, rotate: 0.5 },
|
|
|
|
|
'24': { offset: 5, rotate: 1 },
|
|
|
|
|
'25': { offset: 6, rotate: 2 },
|
|
|
|
|
'26': { offset: 6, rotate: 3.5 },
|
|
|
|
|
'27': { offset: 6, rotate: 5 },
|
|
|
|
|
'28': { offset: 5, rotate: 7 },
|
|
|
|
|
|
|
|
|
|
'48': { offset: -5, rotate: -4 },
|
|
|
|
|
'47': { offset: -6, rotate: -3 },
|
|
|
|
|
'46': { offset: -6, rotate: -2 },
|
|
|
|
|
'45': { offset: -6, rotate: -2 },
|
|
|
|
|
'44': { offset: -5, rotate: -1 },
|
|
|
|
|
'43': { offset: -4, rotate: -0.5 },
|
|
|
|
|
'42': { offset: -4, rotate: -0.25 },
|
|
|
|
|
'41': { offset: -3, rotate: 0 },
|
|
|
|
|
'31': { offset: -3, rotate: 0 },
|
|
|
|
|
'32': { offset: -4, rotate: 0.25 },
|
|
|
|
|
'33': { offset: -4, rotate: 0.5 },
|
|
|
|
|
'34': { offset: -5, rotate: 1 },
|
|
|
|
|
'35': { offset: -6, rotate: 2 },
|
|
|
|
|
'36': { offset: -6, rotate: 2 },
|
|
|
|
|
'37': { offset: -6, rotate: 3 },
|
|
|
|
|
'38': { offset: -5, rotate: 4 },
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-07 18:43:10 +03:30
|
|
|
export function FdiToothChart({
|
|
|
|
|
selected,
|
2026-07-17 00:39:32 +03:30
|
|
|
connectedTeeth,
|
2026-08-19 00:06:21 +03:30
|
|
|
linkedEdges,
|
2026-07-07 18:43:10 +03:30
|
|
|
onToggle,
|
2026-08-19 00:06:21 +03:30
|
|
|
onToggleLink,
|
2026-07-07 18:43:10 +03:30
|
|
|
disabled,
|
|
|
|
|
readOnly = false,
|
|
|
|
|
scale = 1,
|
|
|
|
|
toothColors,
|
|
|
|
|
headerControl,
|
|
|
|
|
compact = false,
|
2026-08-19 23:59:37 +03:30
|
|
|
embedded = false,
|
2026-07-07 18:43:10 +03:30
|
|
|
className = '',
|
|
|
|
|
}: FdiToothChartProps) {
|
2026-06-20 14:51:43 +03:30
|
|
|
const t = useTranslations('treatment');
|
2026-08-19 23:59:37 +03:30
|
|
|
const tCommon = useTranslations('common');
|
2026-05-07 03:40:29 +03:30
|
|
|
const uid = useId().replace(/:/g, '');
|
2026-08-19 23:59:37 +03:30
|
|
|
const [hintOpen, setHintOpen] = useState(false);
|
2026-08-19 00:06:21 +03:30
|
|
|
const archPeak = 8;
|
2026-07-07 18:43:10 +03:30
|
|
|
const interactive = !readOnly && Boolean(onToggle);
|
2026-08-19 00:06:21 +03:30
|
|
|
const linkInteractive = interactive && Boolean(onToggleLink);
|
2026-07-07 18:43:10 +03:30
|
|
|
const isDisabled = disabled || readOnly;
|
2026-05-07 03:40:29 +03:30
|
|
|
|
2026-08-19 00:06:21 +03:30
|
|
|
const toothSizeClass = (fdi: FdiToothId) => toothSize(fdi);
|
2026-05-08 03:58:53 +03:30
|
|
|
|
|
|
|
|
const archOffset = (index: number, count: number, upper?: boolean) => {
|
|
|
|
|
const center = (count - 1) / 2;
|
|
|
|
|
const dist = Math.abs(index - center) / center;
|
|
|
|
|
const curve = (1 - Math.pow(dist, 1.45)) * archPeak;
|
|
|
|
|
return upper ? curve : -curve;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const archRotate = (index: number, count: number) => {
|
|
|
|
|
const center = (count - 1) / 2;
|
|
|
|
|
const normalized = (index - center) / center;
|
2026-08-19 00:06:21 +03:30
|
|
|
return normalized * 4;
|
2026-05-08 03:58:53 +03:30
|
|
|
};
|
|
|
|
|
|
2026-07-07 18:43:10 +03:30
|
|
|
const toothAccent = (fdi: FdiToothId) => toothColors?.[fdi];
|
|
|
|
|
|
|
|
|
|
const numberColorClass = (fdi: FdiToothId, isSel: boolean) => {
|
|
|
|
|
if (!isSel) return 'text-text-muted';
|
|
|
|
|
const accent = toothAccent(fdi);
|
|
|
|
|
return accent ? '' : 'text-primary';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const numberStyle = (fdi: FdiToothId, isSel: boolean): CSSProperties | undefined => {
|
|
|
|
|
if (!isSel) return undefined;
|
|
|
|
|
const accent = toothAccent(fdi);
|
|
|
|
|
return accent ? { color: accent } : undefined;
|
|
|
|
|
};
|
|
|
|
|
|
2026-08-19 00:06:21 +03:30
|
|
|
const edgeIsLinked = (a: FdiToothId, b: FdiToothId): boolean => {
|
|
|
|
|
const key = toothEdgeKey(a, b);
|
|
|
|
|
if (linkedEdges) return linkedEdges.has(key);
|
|
|
|
|
// Read-only fallback: both teeth marked connected.
|
|
|
|
|
return Boolean(connectedTeeth?.has(a) && connectedTeeth?.has(b));
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** Circles sit between neighbors, on the crown side (toward FDI numbers). */
|
|
|
|
|
const EdgeRail = ({ teeth }: { teeth: FdiToothId[] }) => {
|
|
|
|
|
const anyVisible = teeth.some((fdi, i) => {
|
|
|
|
|
const next = teeth[i + 1];
|
|
|
|
|
if (!next || !selected.has(fdi) || !selected.has(next)) return false;
|
|
|
|
|
const linked = edgeIsLinked(fdi, next);
|
|
|
|
|
return linkInteractive || linked;
|
|
|
|
|
});
|
|
|
|
|
if (!anyVisible) return null;
|
2026-07-07 18:43:10 +03:30
|
|
|
|
2026-07-17 11:36:02 +03:30
|
|
|
return (
|
|
|
|
|
<div
|
2026-08-19 00:06:21 +03:30
|
|
|
className={`flex flex-nowrap justify-center ${TOOTH_GAP} min-w-max mx-auto w-fit h-3.5 items-center`}
|
2026-07-17 11:36:02 +03:30
|
|
|
>
|
|
|
|
|
{teeth.map((fdi, i) => {
|
|
|
|
|
const size = toothSizeClass(fdi);
|
2026-08-19 00:06:21 +03:30
|
|
|
const prev = i > 0 ? teeth[i - 1] : undefined;
|
2026-07-17 11:36:02 +03:30
|
|
|
const next = teeth[i + 1];
|
2026-08-19 00:06:21 +03:30
|
|
|
const showEdge = Boolean(next && selected.has(fdi) && selected.has(next));
|
|
|
|
|
const linked = showEdge ? edgeIsLinked(fdi, next!) : false;
|
|
|
|
|
const renderEdge = showEdge && (linkInteractive || linked);
|
|
|
|
|
// Narrow link across this column when both neighboring edges are filled.
|
|
|
|
|
const bridgeLine = Boolean(
|
|
|
|
|
prev &&
|
|
|
|
|
next &&
|
|
|
|
|
selected.has(prev) &&
|
|
|
|
|
selected.has(fdi) &&
|
|
|
|
|
selected.has(next) &&
|
|
|
|
|
edgeIsLinked(prev, fdi) &&
|
|
|
|
|
edgeIsLinked(fdi, next),
|
|
|
|
|
);
|
|
|
|
|
|
2026-07-17 11:36:02 +03:30
|
|
|
return (
|
|
|
|
|
<div
|
2026-08-19 00:06:21 +03:30
|
|
|
key={`e-${fdi}`}
|
|
|
|
|
className="relative h-3.5 flex items-center justify-center"
|
|
|
|
|
style={{ width: `${size.columnWidthRem}rem` }}
|
2026-07-17 11:36:02 +03:30
|
|
|
>
|
2026-08-19 00:06:21 +03:30
|
|
|
{bridgeLine ? (
|
2026-07-17 11:36:02 +03:30
|
|
|
<span
|
2026-08-19 00:06:21 +03:30
|
|
|
className="pointer-events-none absolute inset-x-0 top-1/2 z-0 h-[2px] -translate-y-1/2 bg-primary/75"
|
|
|
|
|
aria-hidden
|
2026-07-17 11:36:02 +03:30
|
|
|
/>
|
|
|
|
|
) : null}
|
2026-08-19 00:06:21 +03:30
|
|
|
{renderEdge ? (
|
2026-08-22 17:49:38 +03:30
|
|
|
<div className={EDGE_MARK_ANCHOR}>
|
|
|
|
|
{linkInteractive ? (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
disabled={isDisabled}
|
|
|
|
|
title={linked ? t('toothUnlinkHint') : t('toothLinkHint')}
|
|
|
|
|
aria-label={
|
2026-08-19 00:06:21 +03:30
|
|
|
linked
|
2026-08-22 17:49:38 +03:30
|
|
|
? t('toothUnlinkAria', { a: fdi, b: next! })
|
|
|
|
|
: t('toothLinkAria', { a: fdi, b: next! })
|
2026-08-19 00:06:21 +03:30
|
|
|
}
|
2026-08-22 17:49:38 +03:30
|
|
|
aria-pressed={linked}
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
onToggleLink?.(fdi, next!);
|
|
|
|
|
}}
|
|
|
|
|
className={`
|
|
|
|
|
h-3.5 w-3.5 shrink-0 rounded-full border-2 transition-colors
|
|
|
|
|
focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50
|
|
|
|
|
${
|
|
|
|
|
linked
|
|
|
|
|
? 'border-primary bg-primary shadow-sm'
|
|
|
|
|
: 'border-primary bg-background-secondary hover:bg-primary/15'
|
|
|
|
|
}
|
|
|
|
|
${isDisabled ? 'opacity-50 cursor-not-allowed' : 'cursor-pointer'}
|
|
|
|
|
`}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<span
|
|
|
|
|
className="h-2.5 w-2.5 shrink-0 rounded-full bg-primary shadow-sm"
|
|
|
|
|
title={t('toothConnectedHint')}
|
|
|
|
|
aria-hidden
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-08-19 00:06:21 +03:30
|
|
|
) : null}
|
2026-05-08 03:58:53 +03:30
|
|
|
</div>
|
2026-07-17 11:36:02 +03:30
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const Row = ({ teeth, upper }: { teeth: FdiToothId[]; upper?: boolean }) => (
|
2026-08-19 00:06:21 +03:30
|
|
|
<div className="flex flex-col items-center min-w-max mx-auto w-fit gap-y-0.5">
|
|
|
|
|
{/* Lower: crowns face numbers above → rail above teeth */}
|
|
|
|
|
{!upper ? <EdgeRail teeth={teeth} /> : null}
|
|
|
|
|
<div className={`flex flex-nowrap justify-center ${TOOTH_GAP} min-w-max mx-auto w-fit`}>
|
2026-07-17 11:36:02 +03:30
|
|
|
{teeth.map((fdi, i) => {
|
|
|
|
|
const kind = getToothShapeKind(fdi);
|
|
|
|
|
const gid = `${uid}-g-${fdi}-${i}`;
|
|
|
|
|
const isSel = selected.has(fdi);
|
|
|
|
|
const size = toothSizeClass(fdi);
|
|
|
|
|
const tweak = TOOTH_TWEAKS[fdi];
|
|
|
|
|
const offsetY = tweak ? tweak.offset : archOffset(i, teeth.length, upper);
|
|
|
|
|
const rotate = tweak ? tweak.rotate : archRotate(i, teeth.length);
|
|
|
|
|
const alignItems = upper ? 'items-end' : 'items-start';
|
|
|
|
|
const accent = toothAccent(fdi);
|
2026-08-19 00:06:21 +03:30
|
|
|
const realistic = Boolean(getRealisticToothAsset(fdi));
|
2026-07-17 11:36:02 +03:30
|
|
|
|
|
|
|
|
const glyph = (
|
|
|
|
|
<ToothGlyph
|
|
|
|
|
fdi={fdi}
|
|
|
|
|
kind={kind}
|
|
|
|
|
gradientId={gid}
|
|
|
|
|
selected={isSel}
|
|
|
|
|
upper={upper}
|
|
|
|
|
mirrored={quadrantMirrored(fdi)}
|
|
|
|
|
upsideDown={upper}
|
2026-08-19 00:06:21 +03:30
|
|
|
className="shrink-0 max-h-full"
|
|
|
|
|
style={{
|
|
|
|
|
width: `${size.glyphWidthRem}rem`,
|
|
|
|
|
height: size.glyphHeightRem === 'auto' ? 'auto' : `${size.glyphHeightRem}rem`,
|
|
|
|
|
}}
|
2026-07-17 11:36:02 +03:30
|
|
|
accentColor={isSel ? accent : undefined}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2026-08-19 23:59:37 +03:30
|
|
|
/** Cover crown/root shift toward the numbers without overlapping neighbors. */
|
|
|
|
|
const hitOverflowPx = Math.abs(offsetY);
|
|
|
|
|
const activateTooth = (shiftKey: boolean) => {
|
|
|
|
|
if (!interactive || isDisabled) return;
|
|
|
|
|
onToggle?.(fdi, { shiftKey });
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-17 11:36:02 +03:30
|
|
|
return (
|
2026-08-19 00:06:21 +03:30
|
|
|
<div
|
|
|
|
|
key={fdi}
|
|
|
|
|
className="flex flex-col items-center"
|
|
|
|
|
style={{ width: `${size.columnWidthRem}rem` }}
|
|
|
|
|
>
|
|
|
|
|
{!upper && realistic ? (
|
|
|
|
|
<div style={{ height: REALISTIC_NUMBER_GAP }} aria-hidden />
|
|
|
|
|
) : null}
|
2026-08-19 23:59:37 +03:30
|
|
|
<div
|
|
|
|
|
className={`group relative box-content flex ${alignItems} justify-center`}
|
|
|
|
|
style={{
|
|
|
|
|
height: '7.25rem',
|
|
|
|
|
paddingBottom: upper ? hitOverflowPx : 0,
|
|
|
|
|
paddingTop: upper ? 0 : hitOverflowPx,
|
|
|
|
|
}}
|
|
|
|
|
>
|
2026-07-17 11:36:02 +03:30
|
|
|
{interactive ? (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
disabled={isDisabled}
|
2026-08-19 23:59:37 +03:30
|
|
|
data-fdi={fdi}
|
2026-07-17 11:36:02 +03:30
|
|
|
onMouseDown={(e) => {
|
2026-07-18 00:02:40 +03:30
|
|
|
if (e.shiftKey) e.preventDefault();
|
2026-07-17 11:36:02 +03:30
|
|
|
}}
|
2026-08-19 23:59:37 +03:30
|
|
|
onPointerDown={(e) => {
|
|
|
|
|
if (e.button !== 0) return;
|
2026-07-17 11:36:02 +03:30
|
|
|
e.preventDefault();
|
2026-08-19 23:59:37 +03:30
|
|
|
e.stopPropagation();
|
|
|
|
|
activateTooth(e.shiftKey);
|
|
|
|
|
}}
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
activateTooth(e.shiftKey);
|
2026-07-17 11:36:02 +03:30
|
|
|
}}
|
|
|
|
|
className={`
|
2026-08-19 23:59:37 +03:30
|
|
|
absolute inset-y-[6%] z-10 rounded-[var(--radius-sm)] bg-transparent select-none touch-manipulation
|
2026-07-17 11:36:02 +03:30
|
|
|
focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50
|
2026-08-19 23:59:37 +03:30
|
|
|
${isDisabled ? 'cursor-not-allowed' : 'cursor-pointer'}
|
2026-07-17 11:36:02 +03:30
|
|
|
`}
|
2026-08-19 23:59:37 +03:30
|
|
|
style={{ left: '22%', right: '22%' }}
|
2026-07-17 11:36:02 +03:30
|
|
|
aria-pressed={isSel}
|
|
|
|
|
aria-label={
|
|
|
|
|
isSel
|
2026-08-19 00:06:21 +03:30
|
|
|
? `${t('toothAria', { fdi })}${t('toothSelectedSuffix')}`
|
2026-07-17 11:36:02 +03:30
|
|
|
: t('toothAria', { fdi })
|
|
|
|
|
}
|
2026-08-19 23:59:37 +03:30
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
<div
|
|
|
|
|
style={{ transform: `translateY(${offsetY}px) rotate(${rotate}deg)` }}
|
|
|
|
|
className={`pointer-events-none ${isDisabled ? 'opacity-50' : ''}`}
|
|
|
|
|
aria-hidden
|
|
|
|
|
>
|
2026-07-17 11:36:02 +03:30
|
|
|
<div
|
2026-08-19 23:59:37 +03:30
|
|
|
className={`
|
|
|
|
|
rounded-[var(--radius-sm)] p-0.5 transition-transform duration-150
|
|
|
|
|
${isSel ? 'scale-105' : ''}
|
|
|
|
|
${
|
|
|
|
|
interactive && !isDisabled
|
|
|
|
|
? '[@media(hover:hover)_and_(pointer:fine)]:group-hover:scale-105'
|
|
|
|
|
: ''
|
|
|
|
|
}
|
|
|
|
|
`}
|
2026-07-17 11:36:02 +03:30
|
|
|
>
|
|
|
|
|
{glyph}
|
|
|
|
|
</div>
|
2026-08-19 23:59:37 +03:30
|
|
|
</div>
|
2026-07-17 11:36:02 +03:30
|
|
|
</div>
|
2026-08-19 00:06:21 +03:30
|
|
|
{upper && realistic ? (
|
|
|
|
|
<div style={{ height: REALISTIC_NUMBER_GAP }} aria-hidden />
|
|
|
|
|
) : null}
|
2026-07-17 11:36:02 +03:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2026-08-19 00:06:21 +03:30
|
|
|
{/* Upper: crowns face numbers below → rail below teeth */}
|
|
|
|
|
{upper ? <EdgeRail teeth={teeth} /> : null}
|
2026-05-07 03:40:29 +03:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2026-08-19 23:59:37 +03:30
|
|
|
const cardClass = embedded
|
|
|
|
|
? 'space-y-2'
|
|
|
|
|
: compact
|
|
|
|
|
? 'rounded-lg border border-border/60 bg-background-secondary/30 p-2 space-y-2'
|
|
|
|
|
: 'surface-card p-3 space-y-3';
|
2026-05-07 03:40:29 +03:30
|
|
|
|
2026-07-07 18:43:10 +03:30
|
|
|
const chartBody = (
|
|
|
|
|
<>
|
2026-06-20 14:51:43 +03:30
|
|
|
<p className="text-[11px] uppercase tracking-wide text-text-muted mb-1 text-center">{t('upperArch')}</p>
|
2026-05-08 03:58:53 +03:30
|
|
|
|
2026-07-17 00:39:32 +03:30
|
|
|
<div className="overflow-x-auto py-1 -mx-1 px-1 select-none">
|
|
|
|
|
<div className="relative isolate min-w-max mx-auto w-fit select-none">
|
2026-05-08 03:58:53 +03:30
|
|
|
<div
|
2026-05-19 23:43:43 +03:30
|
|
|
className="pointer-events-none absolute left-1/2 top-3 bottom-3 w-px -translate-x-1/2 bg-border/70"
|
2026-05-08 03:58:53 +03:30
|
|
|
aria-hidden
|
|
|
|
|
/>
|
2026-05-19 23:43:43 +03:30
|
|
|
<div className="relative z-10 space-y-0">
|
|
|
|
|
<Row teeth={FDI_UPPER_LEFT_TO_RIGHT} upper />
|
2026-08-19 00:06:21 +03:30
|
|
|
<div className={`flex flex-nowrap justify-center ${TOOTH_GAP} ${TOOTH_NUMBER_GAP}`}>
|
2026-08-19 23:59:37 +03:30
|
|
|
{FDI_UPPER_LEFT_TO_RIGHT.map((fdi) => (
|
|
|
|
|
<ToothNumber
|
|
|
|
|
key={`u-${fdi}`}
|
|
|
|
|
fdi={fdi}
|
|
|
|
|
selected={selected.has(fdi)}
|
|
|
|
|
widthRem={toothSizeClass(fdi).columnWidthRem}
|
|
|
|
|
colorClass={numberColorClass(fdi, selected.has(fdi))}
|
|
|
|
|
style={numberStyle(fdi, selected.has(fdi))}
|
|
|
|
|
interactive={interactive}
|
|
|
|
|
disabled={isDisabled}
|
|
|
|
|
onActivate={(shiftKey) => onToggle?.(fdi, { shiftKey })}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2026-05-08 03:58:53 +03:30
|
|
|
</div>
|
2026-05-19 23:43:43 +03:30
|
|
|
|
|
|
|
|
<div className="my-2 h-px w-full bg-border/70" role="separator" aria-hidden />
|
|
|
|
|
|
|
|
|
|
<div className="pt-0.5">
|
2026-08-19 00:06:21 +03:30
|
|
|
<div className={`flex flex-nowrap justify-center ${TOOTH_GAP}`}>
|
2026-08-19 23:59:37 +03:30
|
|
|
{FDI_LOWER_LEFT_TO_RIGHT.map((fdi) => (
|
|
|
|
|
<ToothNumber
|
|
|
|
|
key={`l-${fdi}`}
|
|
|
|
|
fdi={fdi}
|
|
|
|
|
selected={selected.has(fdi)}
|
|
|
|
|
widthRem={toothSizeClass(fdi).columnWidthRem}
|
|
|
|
|
colorClass={numberColorClass(fdi, selected.has(fdi))}
|
|
|
|
|
style={numberStyle(fdi, selected.has(fdi))}
|
|
|
|
|
interactive={interactive}
|
|
|
|
|
disabled={isDisabled}
|
|
|
|
|
onActivate={(shiftKey) => onToggle?.(fdi, { shiftKey })}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
2026-05-19 23:43:43 +03:30
|
|
|
</div>
|
|
|
|
|
<div className={TOOTH_NUMBER_GAP}>
|
|
|
|
|
<Row teeth={FDI_LOWER_LEFT_TO_RIGHT} />
|
|
|
|
|
</div>
|
2026-05-08 03:58:53 +03:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-05-07 03:40:29 +03:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-05-08 03:58:53 +03:30
|
|
|
|
2026-06-20 14:51:43 +03:30
|
|
|
<p className="text-[11px] uppercase tracking-wide text-text-muted mt-1 text-center">{t('lowerArch')}</p>
|
2026-07-07 18:43:10 +03:30
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={`${cardClass} ${className}`}>
|
2026-08-19 23:59:37 +03:30
|
|
|
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-x-2">
|
|
|
|
|
<div className="flex min-w-0 items-center gap-1">
|
2026-07-07 18:43:10 +03:30
|
|
|
<h3 className="text-sm font-semibold text-text-primary">
|
2026-08-19 23:59:37 +03:30
|
|
|
{compact || embedded ? t('toothChartTitleCompact') : t('toothChartTitle')}
|
2026-07-07 18:43:10 +03:30
|
|
|
</h3>
|
2026-08-19 23:59:37 +03:30
|
|
|
{!compact && !embedded ? (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setHintOpen(true)}
|
|
|
|
|
className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full text-text-muted hover:bg-background-card hover:text-text-primary focus:outline-none focus-visible:ring-2 focus-visible:ring-primary/50"
|
|
|
|
|
aria-label={t('toothChartHelpAria')}
|
|
|
|
|
>
|
|
|
|
|
<Info className="h-4 w-4" aria-hidden />
|
|
|
|
|
</button>
|
|
|
|
|
) : null}
|
2026-07-07 18:43:10 +03:30
|
|
|
</div>
|
2026-08-19 23:59:37 +03:30
|
|
|
<div className="flex justify-center">{headerControl}</div>
|
|
|
|
|
<p className="min-w-0 text-[11px] text-text-secondary tabular-nums text-end">
|
|
|
|
|
{t('selectedLabel')}{' '}
|
|
|
|
|
{selected.size === 0 ? t('selectedEmpty') : [...selected].sort().join(', ')}
|
|
|
|
|
</p>
|
2026-07-07 18:43:10 +03:30
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{scale !== 1 ? (
|
2026-08-19 23:59:37 +03:30
|
|
|
<div style={{ zoom: scale }} className="mx-auto w-fit origin-top">
|
2026-07-07 18:43:10 +03:30
|
|
|
{chartBody}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
chartBody
|
|
|
|
|
)}
|
2026-08-19 23:59:37 +03:30
|
|
|
|
|
|
|
|
{hintOpen ? (
|
|
|
|
|
<ResponsiveDialogOverlay onBackdropClick={() => setHintOpen(false)}>
|
|
|
|
|
<ResponsiveDialogPanel
|
|
|
|
|
role="dialog"
|
|
|
|
|
aria-modal="true"
|
|
|
|
|
aria-labelledby={`${uid}-chart-hint-title`}
|
|
|
|
|
maxWidthClass="sm:max-w-md"
|
|
|
|
|
>
|
|
|
|
|
<div className="flex items-start justify-between gap-2 mb-3">
|
|
|
|
|
<h4
|
|
|
|
|
id={`${uid}-chart-hint-title`}
|
|
|
|
|
className="text-sm font-semibold text-text-primary pe-2"
|
|
|
|
|
>
|
|
|
|
|
{t('toothChartHelpAria')}
|
|
|
|
|
</h4>
|
|
|
|
|
<DialogCloseButton onClick={() => setHintOpen(false)} />
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-sm text-text-secondary leading-relaxed">{t('toothChartHint')}</p>
|
|
|
|
|
<div className="mt-4">
|
|
|
|
|
<Button type="button" variant="outline" fullWidth onClick={() => setHintOpen(false)}>
|
|
|
|
|
{tCommon('close')}
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</ResponsiveDialogPanel>
|
|
|
|
|
</ResponsiveDialogOverlay>
|
|
|
|
|
) : null}
|
2026-05-07 03:40:29 +03:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|