/* ============================================================================= * M02_MasterTemplete_Hopyo_Mine.ts * 엑셀 보기 오른쪽 호표 목록 줄 [내 일위대가로](PLAN 807-1 · 요구 699) — `Hopyo_Sheet` 목록 줄이 붙임. * 물음 → 서버 `POST /layers/personal/hopyo-build-all {층, 주인?, 키, 번}`(그 호표 + 하위 → 개인 층 SC · * 부르는 단산 = 가져온 식 SK · 같은 내용 = 있는 것 · 못 이은 줄 = 고정 줄 엑셀 숫자 그대로) → 알림(만든 SC · 단가산출 수 · 엑셀과 같음) * 개인 층은 누구나 씀 · 파일 층 읽기 권한은 서버가 봄 * ========================================================================== */ import { askConfirm, createButton, hideLoadingOverlay, showLoadingOverlay, showToast, } from "@ui/ui_template_elements"; import { t as L } from "@ui/ui_template_locale"; import { call } from "./M02_MasterTemplete_Api_Fetch"; import { at, type HopyoBrief, type HopyoScope } from "./M02_MasterTemplete_Hopyo_Api"; interface MineReply { 만듦: { 번: number; 키: string; 남은줄?: number }[]; 다름: { 번: number }[]; 실패: { 번: number; 까닭?: string }[]; 단가산출?: string[]; } const why = (error: unknown): string => (error instanceof Error ? error.message : String(error)); /** [내 일위대가로] 단추 — `scope` = 파일 층 · `key` = HP 키 */ export function mineButton(scope: HopyoScope, key: string, h: HopyoBrief): HTMLElement { const b = createButton({ label: L("M02_ToMySc"), variant: "ghost", size: "sm", onClick: async (e) => { e.stopPropagation(); if (!(await askConfirm({ message: L("M02_ToMyScAsk").replace("{n}", String(h.번)) }))) return; const file = { 층: scope.layer, ...(scope.owner ? { 주인: scope.owner } : {}) }; showLoadingOverlay(); try { const got = await call( at({ layer: "personal", owner: null }, "/hopyo-build-all"), { method: "POST", body: JSON.stringify({ ...file, 키: key, 번: h.번 }), }, ); const made = got.만듦.find((x) => x.번 === h.번); if (!made) throw new Error(got.실패.map((x) => x.까닭).join(" · ") || "실패"); const same = got.다름.some((x) => x.번 === h.번) ? "다름" : "같음"; const text = L("M02_ToMyScDone") .replace("{k}", made.키) .replace("{s}", String(got.단가산출?.length ?? 0)) .replace("{same}", same); showToast(text, same === "같음" ? "success" : "warning"); } catch (error) { showToast(why(error), "error"); } finally { hideLoadingOverlay(); } }, }); b.setAttribute("data-hopyo-mine", String(h.번)); return b; }