/* ============================================================================= * formula_doc_renew.ts * M01 자동 따라옴 알림(PLAN 836-2 · 859-2 · 요구 904) — M02 단가산출(프로젝트 층 밖)을 열 때 토스트 한 번 · 확인 단추 없음 * 서버 읽기 답 `사본.따라옴`(저장 뒤 M01 몫이 바뀌어 따라온 지문 · 없으면 null) · `사본.갱신`(`M02_Sk_AutoRenew.notes` — * 처리 = 지킴(내가 고친 칸 = 내 값) · 다시복사 · 지워짐(다시 못 얹은 내 고침)) * 같은 바뀜 = 이 브라우저에서 한 번만(localStorage · SK 길마다 따라옴 지문 · 알림 글) · 칸 풍선글(원래 값 · 기초에서 바뀜)은 줄 쌓기 그대로 * ========================================================================== */ import { showToast } from "@ui/ui_template_elements"; import { ft } from "./formula_doc_text"; /** 서버 알림 한 줄 — 토스트는 처리 갈래 수만 셈 */ export interface RenewNote { 키: string; 처리?: string; } const SEEN = "aislo:renew-seen:"; /** 토스트 글 — 반영됨 · 내 값 지킨 칸 n · 다시 못 얹은 내 고침 n */ export function renewText(notes: RenewNote[]): string { const count = (kind: string): number => notes.filter((n) => n.처리 === kind).length; const kept = count("지킴"); const lost = count("지워짐"); return [ ft("Renew_Toast"), ...(kept ? [ft("Renew_Kept_N").replace("{n}", String(kept))] : []), ...(lost ? [ft("Renew_Lost_N").replace("{n}", String(lost))] : []), ].join(" · "); } /** 열 때 한 번 — 새 따라옴 지문(저장 뒤 M01 몫 바뀜) · 새 알림(내가 고친 칸의 위 값 바뀜)일 때만 · * [저장] 하면 따라옴 지문 없음 · 지킨 칸 알림은 같은 글이면 다시 안 띄움(저장소가 막히면 열 때마다) */ export function renewToast( where: string, moved: string | null | undefined, notes: RenewNote[], ): void { const text = notes.length ? JSON.stringify(notes) : ""; let seen: { m?: string; n?: string } = {}; try { seen = JSON.parse(localStorage.getItem(SEEN + where) ?? "{}") as typeof seen; } catch { /* 저장소 막힘 = 열 때마다 */ } if (!(moved && moved !== seen.m) && !(text && text !== seen.n)) return; try { localStorage.setItem(SEEN + where, JSON.stringify({ m: moved || seen.m || "", n: text })); } catch { /* 저장소 막힘 */ } showToast(renewText(notes), "info"); }