import type { PierModel } from '../core/geometry';
import { bearingEdgeDistances, pairEccentricities } from '../core/bearing-layout';
/** Drawing values (A, B of the solplate, mm) of the front and back bearings, to overlay on the model (승인 2026-10-26). */
export interface BearingPlanOverlay {
front: { A: number; B: number };
back: { A: number; B: number };
}
/** Number of pairs the 상세 보기 chips can show (①–⑩ in the mockup). */
export const PAIR_CHIP_LABELS = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩'];
/**
* 교량받침 상세 · 평면 for one pair (승인 2026-10-26): the blocks and solplates are aligned in one row across the 교축
* (x = n), with the actual 교각축 offset of the bearings written as text. The model's solplates are solid, the drawing values
* dashed. 일체 draws one 2500 × 1200 outline; 분리 draws two 1200 × 1200 outlines. Dimensions: C1 (bearing to block edge),
* C2 (between the bearings), C3 (block span). C4 and C5 are the outer margins along the 교축.
*/
export function bearingPlanSvg(m: PierModel, pairIndex: number, overlay?: BearingPlanOverlay): string {
const pair = pairEccentricities(m.blocks)[pairIndex];
if (!pair) return '';
const f = m.blocks.find((b) => b.no === pair.frontNo && b.row === '전열')!;
const k = m.blocks.find((b) => b.no === pair.backNo && b.row === '후열')!;
const nc = (f.n + k.n) / 2;
const sc = (f.s + k.s) / 2;
// The pair is drawn on one line: every block, solplate and bearing sits at the pair's mean 교각축 position.
const X = (n: number) => (n - nc) * 1000;
const Y = (_s: number) => 0;
const eccentricity = Math.abs(f.s - k.s) * 1000;
const parts: string[] = [];
// Axes: 교축 (horizontal, to the right) and 교각축 방향 (vertical, downward).
parts.push(``);
parts.push(``);
parts.push(`교축`);
parts.push(``);
parts.push(``);
parts.push(`교각축 방향`);
// Block outline(s): one row.
const ib = m.integratedBlocks.find((x) => x.frontNo === pair.frontNo);
if (ib) {
parts.push(``);
} else {
for (const b of [f, k]) {
parts.push(``);
}
}
// Solplates: the model's plan (A across the 교축, B along the 교각축), centred on each bearing.
for (const b of [f, k]) {
if (b.plan) {
const { A, B } = b.plan;
parts.push(``);
}
}
// Drawing values overlaid (dashed) on the same bearings (#1 겹쳐 보이게).
if (overlay) {
for (const [b, v] of [[f, overlay.front], [k, overlay.back]] as const) {
parts.push(``);
}
}
// Bearing centres and numbers.
for (const b of [f, k]) {
parts.push(``);
parts.push(`${b.no}`);
}
if (eccentricity > 0.5) {
parts.push(`편심 ${eccentricity.toFixed(0)} mm (교각축 방향, 블록은 한 줄로 맞춤)`);
}
// Dimensions along the bottom: C1 (bearing to block edge), C2 (between the bearings), C1, and C3 (block span).
const dist = bearingEdgeDistances(m);
const d = (no: number) => dist.find((x) => x.no === no)!;
const xLeft = ib ? X(ib.n - 1.25) : X(f.n) - 600;
const xRight = ib ? X(ib.n + 1.25) : X(k.n) + 600;
const dimLine = (x1: number, x2: number, y: number, label: string) =>
`${label}`;
const y1 = 760;
const y2 = 1000;
// C1 and C2 are along the 교축 (horizontal), measured on the drawn positions.
parts.push(dimLine(xLeft, X(f.n), y1, `C1 ${Math.round(X(f.n) - xLeft)}`));
parts.push(dimLine(X(f.n), X(k.n), y1, `C2 ${Math.round(Math.abs(k.n - f.n) * 1000)}`));
parts.push(dimLine(X(k.n), xRight, y1, `C1 ${Math.round(xRight - X(k.n))}`));
parts.push(dimLine(xLeft, xRight, y2, `C3 ${Math.round((xRight - xLeft))}`));
// C4 and C5 as in the 시안: vertical dimensions on the left of the blocks, from the top edge to the bearing row (C4) and
// from the bearing row to the bottom edge (C5). Values: the model's C4 and C5 (outer margins).
const xv = xLeft - 300;
const halfDepth = 600;
const vdim = (y1: number, y2: number, label: string) =>
`${label}`;
parts.push(vdim(-halfDepth, 0, `C4 ${Math.round(d(f.no).leftMm)}`));
parts.push(vdim(0, halfDepth, `C5 ${Math.round(d(k.no).rightMm)}`));
return ``;
}