/* ============================================================================= * M02_MasterTemplete_Labor_RowModal.ts * 일위대가표 사용자 자재 줄 누름 모달(PLAN 723-2 · 요구서_내역16 2장 4 · 5) — 세 칸(`Labor_MatTable` 한 줄) · 가격 다섯 보기. * · 고침 = 그 줄 화면 캐시(저장은 [저장]) · 금액은 표가 다시 셈 → `watch` 로 받아 다시 그림 * · 단가산출(SK) 줄 = `Labor_SkEdit`(프로젝트 사본 = 보기만) · M01 로직 줄 창은 걷음(856-3) * ========================================================================== */ import { el } from "@ui/ui_template_elements"; import { openModal } from "@ui/ui_template_modal"; import type { LaborCalc, LaborMat } from "./M02_MasterTemplete_Labor_Api"; import { setMark } from "./M02_MasterTemplete_Labor_MatMarks"; import { matTable } from "./M02_MasterTemplete_Labor_MatTable"; import { tc } from "./M02_MasterTemplete_Labor_Text"; /** 표가 다시 센 답을 받음 — 돌려준 함수 = 그만 받음 */ export type CalcWatch = (fn: (calc: LaborCalc | null) => void) => () => void; export interface MatModalOptions { mat: LaborMat; watch: CalcWatch; readOnly: boolean; /** 세 칸 고침 뒤 — `money` = 별도계상(금액에 닿음) */ done: (money: boolean) => void; } /** 사용자 자재 줄 — 세 칸(148-4 · 222-1) · 가격 다섯 보기 */ export function openMatModal(o: MatModalOptions): void { const host = el("div", { attrs: { "data-row-mat": o.mat.코드 } }); let calc: LaborCalc | null = null; const draw = (): void => host.replaceChildren( matTable( { mats: [o.mat], calc }, o.readOnly ? { open: () => undefined } : { open: () => undefined, mark: (_i, key, v) => { setMark(o.mat, key, v); o.done(key === "별도계상"); draw(); }, }, ), ); const stop = o.watch((c) => { calc = c; draw(); }); openModal({ title: `${o.mat.코드} ${o.mat.이름 ?? ""}`.trim(), closeLabel: tc("In_Close"), width: "1100px", beforeClose: () => (stop(), true), mount: (body) => body.append(host), }); draw(); }