/* ============================================================================= * line_stack_mine.ts * 줄 쌓기 기계 줄 「복사해 내 기계로」(PLAN 821-3 · 요구서 796 3 장) — M02 개인 층 단가산출만. * 품셈 기계 줄(기계='원문번호') → 그 기계 값을 복사한 내 기계 양식 창 → 저장하면 줄이 그 내 기계로(기계='개인 EQP…') * M01 정본은 그대로 · 내 기계 줄(기계='개인 …') · M01 단가산출 기초 = 단추 없음 * ========================================================================== */ import { createButton } from "@ui/ui_template_button"; import { showToast } from "@ui/ui_template_elements"; import type { Picked } from "../common_util/common_util_line_stack_pick"; import { findSimilar, machineArg, mineElement } from "../M02_MasterTemplete/M02_MyMachine_Api"; import { openMyMachineModal } from "../M02_MasterTemplete/M02_MyMachine_Form"; import { mt } from "../M02_MasterTemplete/M02_MyMachine_Text"; import type { StackTake } from "./line_stack_pick"; /** 기계 줄 연결 → 품셈 기계 원문번호(내 기계 · 기계 입력 없음 = null) */ export function m01MachineNo(link: { 갈래?: string; 입력?: Record; }): string | null { const arg = link.갈래 === "단가산출" ? link.입력?.기계 : undefined; const no = typeof arg === "string" ? arg.trim().replace(/^'|'$/g, "") : ""; return no && !no.startsWith("개인 ") ? no : null; } /** 「복사해 내 기계로」 단추 — 개인 층 SK 품셈 기계 줄만 · 고르면 `done(새 줄 고름)` */ export function toMineButton( take: StackTake | undefined, link: { 갈래?: string; 입력?: Record }, done: (p: Picked) => void, ): HTMLElement | null { const no = m01MachineNo(link); if (!no || take?.layer !== "personal") return null; const b = createButton({ label: mt("To_Mine"), variant: "ghost", size: 24, iconStart: "copy", onClick: async () => { const rows = await findSimilar(take.owner, no).catch(() => []); const seed = rows.find((r) => r.출처 === "M01" && r.원문번호 === no); if (!seed) return showToast(`${mt("Hourly_None")} — ${no}`, "warning"); openMyMachineModal( take.owner, (got) => { const e = mineElement(got.줄, got.시간당); if (!e.로직) return showToast(mt("Pick_Direct"), "warning"); done({ 키: e.로직, 이름: e.이름, 입력: { 기계: machineArg(got.줄.원문번호) }, ...(e.규격 ? { 규격: e.규격 } : {}), }); }, seed, ); }, }); b.dataset.toMine = no; return b; }