Files
Aislo/B09_Estimation/B09_Estimation_UI_Table.ts
2026-09-14 01:59:50 +09:00

67 lines
2.4 KiB
TypeScript

/* =============================================================================
* B09_Estimation_UI_Table.ts
* 옛 B09 화면에서 옮겨 온 **설명 표** 공용 — 머리글 한 줄 · 제목 · 안내 글 · 근거 호버 (PLAN 12장)
*
* - 옛 `B09_Estimation_UI_BaseData.ts` 의 `head`·`note`·`table` 을 그대로 옮김(옛 파일을 지우려고).
* - 칸마다 근거 호버(`keys`·`sheet`) — 사전은 **개발환경에서만** 오고, 없으면 아무 일도 안 함.
* - 숫자 칸은 오른쪽, `leftCols` 칸은 왼쪽(옛 `.b09-left` 와 같음).
* ========================================================================== */
import {
attachProvenance,
markProvenanceCell,
type ProvenanceSheet,
} from "@ui/ui_template_provenance";
import { el } from "./B09_Estimation_UI_Sheet";
/** 금액 글 → 천 단위 쉼표(옛 `money` 그대로 — 소수부를 자르지 않음). */
export function money(value: string | null | undefined): string {
if (value === null || value === undefined || value === "") return "";
const parsed = Number(value);
return Number.isFinite(parsed) ? parsed.toLocaleString("ko-KR") : value;
}
/** 구역 제목. */
export function head(text: string): HTMLElement {
return el("div", "b09s-hint b09s-head", text);
}
/** 안내 한 줄. */
export function note(text: string): HTMLElement {
return el("div", "b09s-hint", text);
}
/** 설명 표 한 장 — 가로로 넘치면 제 칸 안에서만 밀림. */
export function infoTable(
headers: string[],
rows: string[][],
leftCols: number[],
keys?: string[],
sheet?: ProvenanceSheet,
): HTMLElement {
const wrap = el("div", "b09s-wrap");
const table = el("table", "b09s-table b09s-info");
const thead = el("thead");
const headRow = el("tr");
headers.forEach((text, index) => {
headRow.append(el("th", leftCols.includes(index) ? "b09s-left" : "", text));
});
thead.append(headRow);
const tbody = el("tbody");
for (const cells of rows) {
const tr = el("tr");
cells.forEach((text, index) => {
const td = el("td", leftCols.includes(index) ? "b09s-left" : "", text);
const key = keys?.[index];
const column = key ? sheet?.columns[key] : undefined;
if (key && column) markProvenanceCell(td, key, column.tier);
tr.append(td);
});
tbody.append(tr);
}
table.append(thead, tbody);
attachProvenance(table, sheet);
wrap.append(table);
return wrap;
}