/* ============================================================================= * B05_Profile_UI_Drainage_Report.ts * 배수유역 패널이 관 목록이 바뀔 때 밖에 알리는 **관 보고**(`DrainagePipeReport`)를 만든다. * `B05_Profile_UI_Drainage_Panel` 에서 떼어냄(700줄 제한) — 셈은 그대로, 상태를 안 든다. * ========================================================================== */ import type { DetailBasin, PipeSource } from "../B04_PreProcess/B04_PreProcess_Api_Fetch"; import type { createFacilityStore } from "./B05_Profile_UI_Drainage_Facility"; import type { DrainagePipeReport } from "./B05_Profile_UI_Drainage_Panel_Types"; /** 관마다 담당 유역의 배수 유효직경을 붙인다(±0.5m 매칭). 유역 없는 관은 null. * 세월교 검토 유역(bridge_required)도 null — 관 규격을 최대치로 올려 봐야 무의미하고, * 그 지점은 세월교·물넘이로 별도 설계한다(임도설치규정 제12조). * 시설 종류·구간·부속 옵션·출처(source)도 함께 — 통합 목록·사이드 폼이 * 이 목록만으로 편집 화면을 채운다(2026-08-17 단일 폼 통합). */ export function buildPipeReports( pipes: ReadonlyArray<{ chainage_m: number; reason?: string }>, basins: ReadonlyArray, facilityStore: ReturnType, ): DrainagePipeReport[] { return pipes.map((pipe) => { const chainage = Math.round(pipe.chainage_m * 100) / 100; const basin = basins.find((entry) => Math.abs(entry.chainage_m - chainage) < 0.51); const attributes = facilityStore.get(chainage); return { chainage_m: chainage, effective_diameter_mm: basin && !basin.bridge_required ? (basin.pipe_diameter_mm ?? null) : null, // 설계유량은 세월교 검토 유역에도 붙인다 — 물넘이·세월교 단면이 이 값에서 나온다. design_flow_m3s: basin?.design_flow_m3s ?? null, facility: attributes?.facility ?? "pipe", start_m: attributes?.start_m, end_m: attributes?.end_m, source: (pipe.reason || "user") as PipeSource, options: attributes?.options, summary_item: attributes?.summary_item, }; }); }