/* ============================================================================= * M01_MasterData_UI_LogicLab_Est.ts * 「인력·재료·경비」 보기(PLAN 714-2) — 공용 단가산출 계산서(`A00_Common/calc_sheet.ts`)에 시험 계산 읽는 식(`/text`)을 그대로. * 묶음 머리 변수 칸 = 그 묶음 줄들이 쓰는 시험 입력(714-3 `usedInputs`) · 바꾸면 시험 계산 입력 고침 + 다시 셈(정본 안 바뀜) * ========================================================================== */ import { el } from "@ui/ui_template_elements"; import { createText } from "@ui/ui_template_text"; import { calcSheetRows } from "../A00_Common/calc_sheet"; import type { LogicInput } from "./M01_MasterData_UI_Logic_Api"; import { safeReason } from "./M01_MasterData_UI_Logic_Text"; import { usedInputs, type PreviewTextAnswer } from "./M01_MasterData_UI_LogicLab_Formula"; import { tl } from "./M01_MasterData_UI_LogicLab_Text"; export interface EstContext { text: PreviewTextAnswer | null; unit: string; inputs: LogicInput[]; values: Record; onInput?: (name: string, value: string) => void; } export function buildEst(ctx: EstContext): HTMLElement { const host = el("div", { className: "m01lab-est", attrs: { "data-est": "" } }); const text = ctx.text; if (!text || (text.ok && text.계산됨 === false)) { host.append(createText(tl("Formula_Slot"), "muted")); return host; } if (!text.ok) { host.append(createText(safeReason(text.reason), "error")); return host; } const names = ctx.inputs.map((x) => x.이름); host.append( ...calcSheetRows({ 묶음: text.groups, 계: text.계, sumLabel: `${tl("Total")} (${ctx.unit || "원"})`, inputs: ctx.inputs, values: ctx.values, onInput: ctx.onInput, uses: (_, gi) => [ ...new Set(text.groups[gi].줄.flatMap((line) => usedInputs(line, names).map(([n]) => n))), ], }), ); return host; }