import type { PierInput } from './types'; /** * Inputs the user can change on the 2단계 cards (spec §5.2 · plan C2). Each one maps to a field of PierInput. * Extend this list as more cards are enabled; the tracking below works on any of these keys. */ export const EDITABLE_FIELDS = [ { key: 'copingWidthMm', label: '코핑 폭 B', unit: 'mm' }, { key: 'copingLengthMm', label: '코핑 길이 L', unit: 'mm' }, { key: 'pileLengthMm', label: '말뚝 길이', unit: 'mm' }, ] as const; /** Inputs tracked for overrides and pending changes: the numeric cards plus 열별 본수 (an array, compared by value). */ export const TRACKED_KEYS = [...EDITABLE_FIELDS.map((f) => f.key), 'pileRows'] as const; export type EditableKey = (typeof TRACKED_KEYS)[number]; export const FIELD_LABELS: Record = { copingWidthMm: '코핑 폭 B', copingLengthMm: '코핑 길이 L', pileLengthMm: '말뚝 길이', pileRows: '열별 본수', }; /** Keys whose values differ between two inputs. Arrays are compared by value. */ export function changedKeys(a: PierInput, b: PierInput): EditableKey[] { return TRACKED_KEYS.filter((key) => JSON.stringify(a[key]) !== JSON.stringify(b[key])); } /** * The three values a pier carries while it is edited (spec §5.5, plan B1): * - defaults: the values as imported from the sheet (기본값, shown as "기본 3100"). * - input: the values the 3D model was generated from (생성본). * - draft: the values the user currently has in the cards (현재 입력). */ export interface PierValues { defaults: PierInput; input: PierInput; draft: PierInput; } /** Overrides: draft differs from the imported default (주황 표시, "변경 n건" in the card). */ export function overrideKeys(p: PierValues): EditableKey[] { return changedKeys(p.defaults, p.draft); } /** Pending: draft differs from the generated model, so the 3D view is out of date (미반영 변경). */ export function pendingKeys(p: PierValues): EditableKey[] { return changedKeys(p.input, p.draft); } /** Puts one field back to its imported default in the draft. */ export function revertDraft(p: PierValues, key: EditableKey): PierInput { return { ...p.draft, [key]: p.defaults[key] }; }