/* ============================================================================= * formula_doc_renew.ts * M01 자동 따라옴 알림(PLAN 836-2 · 요구 854) — M02 단가산출(프로젝트 층 밖)을 열 때 * M01 에서 바뀐 항목에 얹힌 내 고침을 지우고 다시 복사한 것을 한 번 보임(서버 `M02_Sk_AutoRenew.notes`) * 표 = 항목 · M01 전 → 후 · 지워진 내 고침 · [확인] = 저장(다시 안 뜸) · [나중에] = 다음에 열면 또 뜸 * 고침 없는 항목은 조용히 따라옴(알림 없음) * 848-3(요구 889 · 이음 848-2) — 처리 「지킴」 줄 = 따로 표: 항목 · 위 값 전 → 후 · 내 값(지킴) · [위 값으로] * [위 값으로] = 그 칸의 내 고침을 지움(부르는 쪽 `back` · 캐시 → [저장]) · 「다시복사」 · 「지워짐」 · 옛 꼴 = 위 표 그대로 * ========================================================================== */ import { askConfirm, createButton, el } from "@ui/ui_template_elements"; import { eqText } from "@ui/ui_template_equation"; import { createTable } from "@ui/ui_template_table"; import { ft } from "./formula_doc_text"; /** 서버 알림 한 줄 — 갈래 = 문서(바탕 수식) · 부름(굳힌 부른 문서) · 기계(기계 덮음) */ export interface RenewNote { 키: string; 이름?: string; 갈래?: string; M01?: string[]; 내고침?: string[]; /** 848-2 — 지킴 · 다시복사 · 지워짐(없음 = 옛 꼴) */ 처리?: string; /** 지킴 — 기계덮음 열쇠 · 칸 경로(`값.<칸>` · 조종원 · 잡품 · `작업량.*`) · 보일 이름 · 위 층 전 · 후 · 내 값 */ 열쇠?: string; 경로?: string; 칸?: string; 층?: string; 전?: unknown; 후?: unknown; 내값?: unknown; /** 다시복사 · 지워짐 — 다시 얹은 고침 */ 다시얹음?: string[]; } export const KEPT = "지킴"; /** 칸 안 여러 줄 — 줄마다 한 덩이 */ const lines = (xs: string[] | undefined): HTMLElement => el("div", { children: (xs ?? []).map((t) => el("div", { text: t })) }); /** 값 글 — 수 · 글 · 줄 목록(인력 · 잡품 = 이름 수량) */ export function noteValue(v: unknown): string { if (v === undefined || v === null || v === "") return "—"; if (typeof v === "number") return eqText(v); if (Array.isArray(v)) return v .map((r) => { if (!r || typeof r !== "object") return String(r); const x = r as Record; const qty = x.인 ?? x.수량; return [x.이름 ?? x.키 ?? x.줄, qty === undefined ? "" : noteValue(qty), x.율 === undefined ? "" : `${noteValue(x.율)}%`] // prettier-ignore .filter((t) => t !== "" && t !== undefined) .join(" "); }) .join(", "); return typeof v === "object" ? JSON.stringify(v) : String(v); } /** 알림 창 — 확인이면 true(부르는 쪽이 저장) · `back` = 지킴 줄 [위 값으로](누른 줄을 닫을 때 한 번에) */ export async function askRenew( notes: RenewNote[], back?: (picked: RenewNote[]) => void, ): Promise { const kept = notes.filter((n) => n.처리 === KEPT && n.열쇠 && n.경로); const rest = notes.filter((n) => !kept.includes(n)); const picked: RenewNote[] = []; const parts: HTMLElement[] = []; if (kept.length) { const table = createTable( [ { label: ft("Renew_Item"), width: "28%" }, { label: ft("Renew_Upper") }, { label: ft("Renew_Kept") }, { label: "", width: "120px" }, ], kept.map((n) => { const b = createButton({ label: ft("Renew_Back"), variant: "ghost", size: 24, iconStart: "undo", onClick: () => { picked.push(n); b.disabled = true; b.setAttribute("aria-pressed", "true"); }, }); b.dataset.renewBack = `${n.열쇠}|${n.경로}`; return [ lines([n.이름 || n.키, n.칸 || n.경로 || ""]), `${noteValue(n.전)} → ${noteValue(n.후)}`, noteValue(n.내값), ...(back ? [b] : [""]), ]; }), { density: "data" }, ); table.dataset.renewKept = String(kept.length); parts.push(table); } if (rest.length) { const table = createTable( [ { label: ft("Renew_Item"), width: "28%" }, { label: ft("Renew_M01") }, { label: ft("Renew_Mine") }, ], rest.map((n) => [ lines([n.이름 || n.키, n.키]), lines(n.M01), lines([...(n.내고침 ?? []), ...(n.다시얹음 ?? []).map((t) => `↻ ${t}`)]), ]), { density: "data" }, ); table.dataset.renewNotes = String(rest.length); parts.push(table); } const ok = await askConfirm({ title: ft("Renew_Title"), message: ft(kept.length ? "Renew_Ask_Kept" : "Renew_Ask"), okLabel: ft("Renew_Ok"), cancelLabel: ft("Renew_Later"), detail: parts.length === 1 ? parts[0] : el("div", { children: parts }), }); if (picked.length) back?.(picked); return ok; }